Fixed #6022 (Defect: False positive due to bug in determining bounds of for loop 'for (i = 2; i < 1; ++i)')
This commit is contained in:
parent
5cc2e247bb
commit
b2288e5ada
|
@ -1371,6 +1371,8 @@ static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, con
|
||||||
MathLib::bigint num1(0), num2(0), numAfter(0);
|
MathLib::bigint num1(0), num2(0), numAfter(0);
|
||||||
|
|
||||||
if (valueFlowForLoop1(tok, &varid, &num1, &num2, &numAfter)) {
|
if (valueFlowForLoop1(tok, &varid, &num1, &num2, &numAfter)) {
|
||||||
|
if (num1 > num2)
|
||||||
|
continue;
|
||||||
valueFlowForLoopSimplify(bodyStart, varid, num1, tokenlist, errorLogger, settings);
|
valueFlowForLoopSimplify(bodyStart, varid, num1, tokenlist, errorLogger, settings);
|
||||||
valueFlowForLoopSimplify(bodyStart, varid, num2, tokenlist, errorLogger, settings);
|
valueFlowForLoopSimplify(bodyStart, varid, num2, tokenlist, errorLogger, settings);
|
||||||
valueFlowForLoopSimplifyAfter(tok, varid, numAfter, tokenlist, errorLogger, settings);
|
valueFlowForLoopSimplifyAfter(tok, varid, numAfter, tokenlist, errorLogger, settings);
|
||||||
|
|
|
@ -1032,6 +1032,14 @@ private:
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" for (int x = 2; x < 1; x++)\n"
|
||||||
|
" a[x] = 0;\n" // <- not 2
|
||||||
|
" b = x;\n" // <- TODO: this is 2
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 2));
|
||||||
|
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 2));
|
||||||
|
|
||||||
code = "void f(int a) {\n"
|
code = "void f(int a) {\n"
|
||||||
" for (int x = a; x < 10; x++)\n"
|
" for (int x = a; x < 10; x++)\n"
|
||||||
" a[x] = 0;\n"
|
" a[x] = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue