Fixed two issues in CheckSizeof::checkSizeofForPointerSize()
This commit is contained in:
parent
598809a834
commit
49f6231756
|
@ -134,13 +134,13 @@ void CheckSizeof::checkSizeofForPointerSize()
|
|||
} else if (Token::simpleMatch(tok, "return calloc (")) {
|
||||
tokSize = tok->tokAt(3)->nextArgument();
|
||||
tokFunc = tok->next();
|
||||
} else if (Token::simpleMatch(tok, "memset (")) {
|
||||
} else if (Token::simpleMatch(tok, "memset (") && tok->strAt(-1) != ".") {
|
||||
variable = tok->tokAt(2);
|
||||
tokSize = variable->nextArgument();
|
||||
if (tokSize)
|
||||
tokSize = tokSize->nextArgument();
|
||||
tokFunc = tok;
|
||||
} else if (Token::Match(tok, "memcpy|memcmp|memmove|strncpy|strncmp|strncat (")) {
|
||||
} else if (Token::Match(tok, "memcpy|memcmp|memmove|strncpy|strncmp|strncat (") && tok->strAt(-1) != ".") {
|
||||
variable = tok->tokAt(2);
|
||||
variable2 = variable->nextArgument();
|
||||
if (!variable2)
|
||||
|
@ -158,7 +158,7 @@ void CheckSizeof::checkSizeofForPointerSize()
|
|||
}
|
||||
}
|
||||
|
||||
if (!variable)
|
||||
if (!variable || !tokSize)
|
||||
continue;
|
||||
|
||||
while (Token::Match(variable, "%var% ::|."))
|
||||
|
@ -199,6 +199,9 @@ void CheckSizeof::checkSizeofForPointerSize()
|
|||
while (Token::Match(tokSize, "%var% ::|."))
|
||||
tokSize = tokSize->tokAt(2);
|
||||
|
||||
if (Token::Match(tokSize, "%var% [|("))
|
||||
continue;
|
||||
|
||||
// Now check for the sizeof usage. Once here, everything using sizeof(varid) or sizeof(&varid)
|
||||
// looks suspicious
|
||||
// Do it for first variable
|
||||
|
|
|
@ -524,6 +524,19 @@ private:
|
|||
" memset(pIntArray, 0, sizeof(pIntArray));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void FreeFileName(const char *s) {\n"
|
||||
" CxString tbuf;\n"
|
||||
" const char *p;\n"
|
||||
" memcpy(s, siezof(s));\n" // non-standard memcpy
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" module_config_t *tab = module;\n"
|
||||
" memset(tab + confsize, 0, sizeof(tab[confsize]));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkPointerSizeofStruct() {
|
||||
|
|
Loading…
Reference in New Issue