* Fix #9648 FP sizeofDivisionMemfunc when result is multiplied again with sizeof later * Format
This commit is contained in:
parent
938517b80a
commit
8203c74c40
|
@ -165,6 +165,19 @@ void CheckSizeof::checkSizeofForPointerSize()
|
||||||
if (vt && vt->type == ValueType::CHAR && vt->pointer == 0)
|
if (vt && vt->type == ValueType::CHAR && vt->pointer == 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
auto hasMultiplication = [](const Token* parTok) -> bool {
|
||||||
|
while (parTok) { // Allow division if followed by multiplication
|
||||||
|
if (parTok->isArithmeticalOp() && parTok->str() == "*") {
|
||||||
|
for (const Token* szTok : { parTok->astOperand1(), parTok->astOperand2() })
|
||||||
|
if (Token::simpleMatch(szTok, "(") && Token::simpleMatch(szTok->previous(), "sizeof"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
parTok = parTok->astParent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if (hasMultiplication(tok2->astParent()))
|
||||||
|
continue;
|
||||||
|
|
||||||
divideBySizeofError(tok2, tokFunc->str());
|
divideBySizeofError(tok2, tokFunc->str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -785,6 +785,14 @@ private:
|
||||||
" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\n"
|
" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n" // #9648
|
||||||
|
" int a[5] = { 0 };\n"
|
||||||
|
" int b[5];\n"
|
||||||
|
" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\n"
|
||||||
|
" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void sizeofVoid() {
|
void sizeofVoid() {
|
||||||
|
|
Loading…
Reference in New Issue