Skip to content

Commit

Permalink
Fix FPs incorrectStringBooleanError
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 8, 2023
1 parent 48a7a43 commit 8d3509e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[?:]"))
Expand Down
6 changes: 5 additions & 1 deletion lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,12 @@ class TestString : public TestFixture {
" 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() {
Expand Down

0 comments on commit 8d3509e

Please sign in to comment.