From 2251a681daba6463fcddaa014c0555e28d0acb5c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:02:44 +0200 Subject: [PATCH 1/2] Update teststring.cpp --- test/teststring.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/teststring.cpp b/test/teststring.cpp index 59202c4a745..9a00c1944cb 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -808,6 +808,12 @@ class TestString : public TestFixture { " MACRO(false && \"abc\");\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\n" // #13093 + "void f(const char* p) {\n" + " if (strequ(p, \"ALL\")) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void deadStrcmp() { From c3671ae2c795d6e8f45513b56e6996a538a06a3c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:04:34 +0200 Subject: [PATCH 2/2] Update checkstring.cpp --- lib/checkstring.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index dc60d40f22d..7062a5805f7 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -254,8 +254,11 @@ void CheckString::strPlusCharError(const Token *tok) static bool isMacroUsage(const Token* tok) { if (const Token* parent = tok->astParent()) { - while (parent && (parent->isCast() || parent->str() == "&&")) + while (parent && (parent->isCast() || parent->str() == "&&")) { + if (parent->isExpandedMacro()) + return true; parent = parent->astParent(); + } if (!parent) return false; if (parent->isExpandedMacro())