はじめに
C++の静的解析ツール「cppcheck」でソースコードを静的解析した場合に、以下の警告がでることがあります。
(warning) Found calculation inside sizeof().
cppcheckのバージョン
- v1.65
サンプルプログラム
以下のソースプログラムを解析にかけると表示されます。
int _tmain(int argc, _TCHAR* argv[]) { char tmp[5]; memcpy(tmp, "hoge", sizeof(tmp-1)); return 0; }
上記の感じで、sizeof演算子の中でサイズの調整をしてしまった場合に警告が表示されます。
関連記事
- C6305の解説 sizeof 数と countof 数の間で不一致が発生した可能性があります
- 【cppcheck】Variable 'xxx' is reassigned a value before the old one has been used.
- Visual C++ 2013でDLLを作成して動的読み込みしてみる。
- 【cppcheck】The code contains characters that are unhandled. Neither unicode nor extended ASCII are supported.
- 【cppcheck】Size of pointer 'xxx' used instead of size of its data.