Fix #11976 FP incorrectStringBooleanError in assert (#5415)

This commit is contained in:
chrchr-github 2023-09-12 10:05:51 +02:00 committed by GitHub
parent 02b836baad
commit 18ee859737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -2246,7 +2246,7 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn)
parent = parent->astParent();
// passing variable to subfunction?
if (Token::Match(parent, "[*[(,{]"))
if (Token::Match(parent, "[*[(,{]") || Token::Match(parent, "%oror%|&&"))
;
else if (Token::simpleMatch(parent, ":")) {
while (Token::Match(parent, "[?:]"))

View File

@ -255,9 +255,13 @@ void CheckString::strPlusCharError(const Token *tok)
static bool isMacroUsage(const Token* tok)
{
if (const Token* parent = tok->astParent()) {
while (parent && parent->isCast())
parent = parent->astParent();
if (!parent)
return false;
if (parent->isExpandedMacro())
return true;
if (parent->isUnaryOp("!")) {
if (parent->isUnaryOp("!") || parent->isComparisonOp()) {
int argn{};
const Token* ftok = getTokenArgumentFunction(parent, argn);
if (ftok && !ftok->function())

View File

@ -799,6 +799,12 @@ private:
" return false;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(const int* p, const int* q) {\n"
" assert((p != NULL && q != NULL) || !\"abc\");\n"
" ASSERT((void*)(\"def\") == 0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void deadStrcmp() {