diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index b5316dbee00..315ecceb4a2 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1986,7 +1986,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange() default: break; } - if (bits == 0 || bits >= 64) + if (bits == 0 || bits >= 63) continue; const auto typeMinValue = (typeTok->valueType()->sign == ValueType::Sign::UNSIGNED) ? 0 : (-(1LL << (bits-1))); diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index ebdfc70a50d..023a56c2496 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -208,7 +208,7 @@ namespace { bool checkThen, checkElse; std::tie(checkThen, checkElse) = evalCond(condTok); if (!checkThen && !checkElse) { - if (!traverseUnknown && stopOnCondition(condTok) && stopUpdates()) { + if (!traverseUnknown && stopOnCondition(condTok) && tok->str() != "?" && stopUpdates()) { return Progress::Continue; } checkThen = true; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index f4d0ca61813..f9ec1135fb6 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1403,7 +1403,9 @@ class TestNullPointer : public TestFixture { " if (x) p = q;\n" " if (y ? p->x : p->y) { }\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: p\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (warning) Possible null pointer dereference: p [nullPointer]\n" + "[test.cpp:4:20]: (warning) Possible null pointer dereference: p [nullPointer]\n", + errout_str()); } void nullpointer21() { // #4038 - fp: if (x) p=q; else return; @@ -3372,7 +3374,7 @@ class TestNullPointer : public TestFixture { " if (!p) {}\n" " return q ? p->x : 0;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:16]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("int f(ABC *p) {\n" // FP : return && " if (!p) {}\n" @@ -3392,6 +3394,20 @@ class TestNullPointer : public TestFixture { " pointer = func(sizeof pointer[0]);\n" "}"); ASSERT_EQUALS("", errout_str()); + + check("struct T {\n" // #14164 + " T* next;\n" + " char op;\n" + "};\n" + "void h(int, char);\n" + "void g(const T* tok, bool b) {\n" + " if (tok->op == '<') {\n" + " while ((tok = tok->next) && tok->op != '>') {}\n" + " }\n" + " h(b ? 1 : 0, tok->op);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:8:21] -> [test.cpp:10:18]: (warning) Either the condition 'tok=tok->next' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", + errout_str()); } // Test CheckNullPointer::nullConstantDereference