Fix FP divideSizeof (#4003)

This commit is contained in:
chrchr-github 2022-04-11 20:41:59 +02:00 committed by GitHub
parent 07fb6c1853
commit bf6bcafc56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -387,7 +387,9 @@ void CheckSizeof::suspiciousSizeofCalculation()
divideSizeofError(tok);
else if (varTok && varTok->str() == "*") {
const Token* arrTok = lPar->astParent()->astOperand1();
arrTok = arrTok ? arrTok->next() : nullptr;
arrTok = arrTok ? arrTok->astOperand2() : nullptr;
while (Token::simpleMatch(arrTok, "."))
arrTok = arrTok->astOperand2();
var = arrTok ? arrTok->variable() : nullptr;
if (var && var->isPointer() && !var->isArray())
divideSizeofError(tok);

View File

@ -456,6 +456,16 @@ private:
" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct S {\n"
" struct T {\n"
" char* c[3];\n"
" } t[1];\n"
"};\n"
"void f(S* s) {\n"
" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkPointerSizeof() {