Skip to content

Commit 91151ed

Browse files
Fix #13093 FP incorrectStringBooleanError for nullptr check in macro (#6793)
1 parent ac6f436 commit 91151ed

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkstring.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ void CheckString::strPlusCharError(const Token *tok)
254254
static bool isMacroUsage(const Token* tok)
255255
{
256256
if (const Token* parent = tok->astParent()) {
257-
while (parent && (parent->isCast() || parent->str() == "&&"))
257+
while (parent && (parent->isCast() || parent->str() == "&&")) {
258+
if (parent->isExpandedMacro())
259+
return true;
258260
parent = parent->astParent();
261+
}
259262
if (!parent)
260263
return false;
261264
if (parent->isExpandedMacro())

test/teststring.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ class TestString : public TestFixture {
808808
" MACRO(false && \"abc\");\n"
809809
"}\n");
810810
ASSERT_EQUALS("", errout_str());
811+
812+
check("#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\n" // #13093
813+
"void f(const char* p) {\n"
814+
" if (strequ(p, \"ALL\")) {}\n"
815+
"}\n");
816+
ASSERT_EQUALS("", errout_str());
811817
}
812818

813819
void deadStrcmp() {

0 commit comments

Comments
 (0)