Skip to content

Commit 18ee859

Browse files
Fix #11976 FP incorrectStringBooleanError in assert (#5415)
1 parent 02b836b commit 18ee859

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn)
22462246
parent = parent->astParent();
22472247

22482248
// passing variable to subfunction?
2249-
if (Token::Match(parent, "[*[(,{]"))
2249+
if (Token::Match(parent, "[*[(,{]") || Token::Match(parent, "%oror%|&&"))
22502250
;
22512251
else if (Token::simpleMatch(parent, ":")) {
22522252
while (Token::Match(parent, "[?:]"))

lib/checkstring.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ void CheckString::strPlusCharError(const Token *tok)
255255
static bool isMacroUsage(const Token* tok)
256256
{
257257
if (const Token* parent = tok->astParent()) {
258+
while (parent && parent->isCast())
259+
parent = parent->astParent();
260+
if (!parent)
261+
return false;
258262
if (parent->isExpandedMacro())
259263
return true;
260-
if (parent->isUnaryOp("!")) {
264+
if (parent->isUnaryOp("!") || parent->isComparisonOp()) {
261265
int argn{};
262266
const Token* ftok = getTokenArgumentFunction(parent, argn);
263267
if (ftok && !ftok->function())

test/teststring.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,12 @@ class TestString : public TestFixture {
799799
" return false;\n"
800800
"}\n");
801801
ASSERT_EQUALS("", errout.str());
802+
803+
check("void f(const int* p, const int* q) {\n"
804+
" assert((p != NULL && q != NULL) || !\"abc\");\n"
805+
" ASSERT((void*)(\"def\") == 0);\n"
806+
"}\n");
807+
ASSERT_EQUALS("", errout.str());
802808
}
803809

804810
void deadStrcmp() {

0 commit comments

Comments
 (0)