Fixed #7582 (false positive: Division by result of sizeof(). strncpy() expects a size in bytes)
This commit is contained in:
parent
7a183779e2
commit
91e38f3eb9
|
@ -157,6 +157,8 @@ void CheckSizeof::checkSizeofForPointerSize()
|
|||
|
||||
if (tokFunc && tokSize) {
|
||||
for (const Token* tok2 = tokSize; tok2 != tokFunc->linkAt(1); tok2 = tok2->next()) {
|
||||
if (tok2->str() == "sizeof")
|
||||
break;
|
||||
if (Token::simpleMatch(tok2, "/ sizeof"))
|
||||
divideBySizeofError(tok2, tokFunc->str());
|
||||
}
|
||||
|
|
|
@ -623,6 +623,12 @@ private:
|
|||
" return malloc(num / sizeof(Foo));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead?\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char str[100];\n"
|
||||
" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sizeofVoid() {
|
||||
|
|
Loading…
Reference in New Issue