Skip to content

Commit 01c29ed

Browse files
committed
Fixed danmar#5518 (FP regression in 1.64: Array accessed out of bounds)
1 parent a3f5beb commit 01c29ed

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/checknullpointer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
567567
if (!value)
568568
continue;
569569

570+
if (!_settings->inconclusive && value->inconclusive)
571+
continue;
572+
570573
// Is pointer used as function parameter?
571574
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
572575
const Token *ftok = tok->previous();

lib/valueflow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value,
7878
// if value is 0 and the library says 0 is invalid => do not bailout
7979
if (value.intvalue==0 && settings->library.isnullargbad(tok->str(), 1+argnr))
8080
return false;
81-
// inconclusive => don't bailout
82-
if (inconclusive && !addressOf && settings->inconclusive) {
81+
// addressOf => inconclusive
82+
if (!addressOf) {
8383
*inconclusive = true;
8484
return false;
8585
}
@@ -506,7 +506,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
506506
}
507507

508508
// noreturn scopes..
509-
if (number_of_if > 0 &&
509+
if ((number_of_if > 0 || Token::findmatch(tok2, "%varid%", start, varid)) &&
510510
(Token::findmatch(start, "return|continue|break", end) ||
511511
(Token::simpleMatch(end,"} else {") && Token::findmatch(end, "return|continue|break", end->linkAt(2))))) {
512512
if (settings->debugwarnings)

test/testvalueflow.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class TestValueFlow : public TestFixture {
271271
"}";
272272
ASSERT_EQUALS(true, testValueOfX(std::string("void setx(int x);")+code, 2U, 1));
273273
ASSERT_EQUALS(false, testValueOfX(std::string("void setx(int &x);")+code, 2U, 1));
274-
ASSERT_EQUALS(false, testValueOfX(code, 2U, 1));
274+
ASSERT_EQUALS(true, testValueOfX(code, 2U, 1));
275275

276276
code = "void f(char* x) {\n"
277277
" strcpy(x,\"abc\");\n"
@@ -569,6 +569,22 @@ class TestValueFlow : public TestFixture {
569569
"}";
570570
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
571571

572+
code = "void f() {\n"
573+
" int x = 32;\n"
574+
" if (x>=32) return;\n"
575+
" a[x]=0;\n"
576+
"}";
577+
ASSERT_EQUALS(false, testValueOfX(code, 4U, 32));
578+
579+
code = "void f() {\n"
580+
" int x = 32;\n"
581+
" if (x>=32) {\n"
582+
" a[x] = 0;\n" // <- should have possible value 32
583+
" return;\n"
584+
" }\n"
585+
"}";
586+
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 32));
587+
572588
// multivariables
573589
code = "void f(int a) {\n"
574590
" int x = a;\n"

0 commit comments

Comments
 (0)