bzeroCalled
ID:bzeroCalled
Obsolescent function 'bzero' called. It is recommended to use 'memset' instead..
これは簡単。
bzero は非推奨なのです。
いずれなくなる運命にある関数なので、可能であれば memset に置き換えていきましょう。
catchExceptionByValue
ID: catchExceptionByValue
The exception is caught by value. It could be caught as a (const) reference which is usually recommended in C++.
「try ~ catch」の処理ですわな。
try
{
処理;
}
catch (value)
{
例外処理:
}
てなことを書いておいて、「catch」するものは、「const」ではないとだめということかしら?(← かなりいい加減)
clarifyCondition
ID:clarifyCondition
Boolean result is used in bitwise operation. Clarify expression with parentheses.
実は、これ、よくわからんのです。
CLI で
array<byte>^ arrayVal = static_cast<array<byte>^>(value);
という (value は変数で上位からの呼び出し時に決められます) 記述をしていると出力されました。
どこか問題なのだろうか?
constParameter
ID: constParameter
Parameter 'sCreDate' can be declared with const
「VC++」を使用していて
void function(CString& cparam)
{
処理;
}
てな感じで書いていたら、出力されました。
「const」つけなきゃだめってこと?
中で、いじるんだけどな・・・。
copyCtorPointerCopying
ID:copyCtorPointerCopying
Value of pointer 'pread', which points to allocated memory, is copied in copy constructor instead of allocating new memory.
これは
#include <limits.h>
#include <stdio.h>
class Sample
{
public:
Sample(const char *aname);
Sample::Sample(const Sample& other);
virtual ~Sample(void);
Sample &operator=(const Sample &other)
{
if (this != &other)
{
pread = other.pread;
}
return *this;
}
private:
FILE *pread; // ファイル
};
Sample::Sample(const Sample& other)
{
this->pread = other.pread;
}
Sample::Sample(const char *aname)
{
char afile[PATH_MAX]; // ファイル名
sprintf(afile, "%s.c", aname);
if ((pread = fopen(afile, "r")) == NULL)
{
perror(afile);
return;
}
}
Sample::~Sample(void)
{
fclose(pread);
}
というソースで指摘されます。
27行目がいかんのですね。人様の使っているポインタを自分のものにしようとしているのだからまずいですね。
cstyleCast
ID: cstyleCast
C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected. See also: https://www.securecoding.cert.org/confluence/display/cplusplus/EXP05-CPP.+Do+not+use+C-style+casts.
てなことを書かれております。
他の型や、「void」を使用したポインタ変数を使用して・・・。
struct tag
{
なんちゃら・・・;
} *value;
void* p;
p = malloc(sizeof(tag));
value = (tag *)p;
てなことを、書くと、10行目が、「C スタイルのキャストだ」ってことになるようですが・・・。
これを逃れる術は、まだ持ち合わせていないのです(2020年3月24日)。
duplicateBranch
ID:duplicateBranch
Found duplicate branches for 'if' and 'else'.
if (a == 0)
{
b = 0;
}
else
{
b = 0;
}
のように if と else でまったく同じ処理を記述していると出力されます。
実際のケースでは、複雑な事情があったんですけど・・・。ここではその説明は割愛します。
duplicateBreak
ID:duplicateBreak
Consecutive return, break, continue, goto or throw statements are unnecessary.
void sub(int a)
{
int b = 0;
switch(a)
{
case 0:
if (b == 0)
{
return;
break;
}
break;
case 1:
break;
default:
break;
}
}
ってなときに出力されます。
11行目の break は不要ですと言っているわけです。。
「スタイル」というレベルの微妙なとこなんですけど。
わたしはこれはそのままにします。
何らかの対応で 13行目の箇所に処理が入ることがありえるからです。
duplicateExpression
ID:duplicateExpression
Same expression on both sides of '-'.
#include <stdio.h>
int main(int argc, char* argv[])
{
int a[10] = {};
・・・
a[1-1] = 0;
a[2-1] = 0;
・・・
return 0;
}
てなコードを書いて出力されました。
9行目ですね。1 - 1 は 0 に決まってんじゃん。てなことでしょうか。
算数の基本ですね。A - A = 0 なので、引き算する意味がないでしょってことです。
実際は、意図的にやっていることなので無視しました。
knownConditionTrueFalse
ID:knownConditionTrueFalse
Condition '式' is always true
下記のようなコーディングで出力されます。
void hoge(int* n1)
{
int n2 = 0;
if (n2 == 0)
{
n1 = NULL;
}
}
実際のソースがこんなに短けりゃ、すぐにわかるってもんですが・・・。
3行目で初期化した後になんの変更もないまま比較しているので 5行目は「常に真ですよ」ってことです。
missingOverride
ID: missingOverride
The function '関数名' overrides a function in a base class but is not marked with a 'override' specifier.
う~ん。これは、クラスのメソッドで
class className
{
public:
className(); // コンストラクタ
~className(); // デストラクタ
virtual void method(...);
}
てなことを書いておると、7行目に対して、表示されます。
「『virtual』メソッドで定義しているけれども、オーバライドしたメソッドが存在しないよ」と言っているのかしらん。