Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
3 changes: 3 additions & 0 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ namespace {
bool checkThen, checkElse;
std::tie(checkThen, checkElse) = evalCond(condTok);
if (!checkThen && !checkElse) {
const bool oldAnalyzeOnly = analyzeOnly;
if (!traverseUnknown && stopOnCondition(condTok) && stopUpdates()) {
return Progress::Continue;
}
if (tok->str() == "?")
Comment thread
chrchr-github marked this conversation as resolved.
Outdated
analyzeOnly = oldAnalyzeOnly;
checkThen = true;
checkElse = true;
}
Expand Down
16 changes: 15 additions & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3372,7 +3372,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"
Expand All @@ -3392,6 +3392,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
Expand Down