Fix FP if sizeof is used without parentheses on struct members
Right now we only support checking basic pointer types. Pointers inside structs are not supported yet. Consider the tokens "foo@1 . bar@2", Token::Match( "sizeof ( %varid% )" ) won't match it. Token::Match( "sizeof %varid%" ) did match it -> FP.
This commit is contained in:
parent
93ac5a41cd
commit
dca65ce3da
|
@ -190,10 +190,10 @@ void CheckSizeof::checkSizeofForPointerSize()
|
|||
// looks suspicious
|
||||
// Do it for first variable
|
||||
if (variable && (Token::Match(tokSize, "sizeof ( &| %varid% )", variable->varId()) ||
|
||||
Token::Match(tokSize, "sizeof &| %varid%", variable->varId()))) {
|
||||
Token::Match(tokSize, "sizeof &| %varid% !!.", variable->varId()))) {
|
||||
sizeofForPointerError(variable, variable->str());
|
||||
} else if (variable2 && (Token::Match(tokSize, "sizeof ( &| %varid% )", variable2->varId()) ||
|
||||
Token::Match(tokSize, "sizeof &| %varid%", variable2->varId()))) {
|
||||
Token::Match(tokSize, "sizeof &| %varid% !!.", variable2->varId()))) {
|
||||
sizeofForPointerError(variable2, variable2->str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
TEST_CASE(sizeofsizeof);
|
||||
TEST_CASE(sizeofCalculation);
|
||||
TEST_CASE(checkPointerSizeof);
|
||||
TEST_CASE(checkPointerSizeofStruct);
|
||||
TEST_CASE(sizeofDivisionMemset);
|
||||
TEST_CASE(sizeofForArrayParameter);
|
||||
TEST_CASE(sizeofForNumericParameter);
|
||||
|
@ -502,6 +503,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkPointerSizeofStruct() {
|
||||
check("void f() {\n"
|
||||
" struct foo *ptr;\n"
|
||||
" memset( ptr->bar, 0, sizeof ptr->bar );\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sizeofDivisionMemset() {
|
||||
check("void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\n"
|
||||
" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\n"
|
||||
|
|
Loading…
Reference in New Issue