File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -9197,6 +9197,9 @@ static std::vector<ValueFlow::Value> isOutOfBoundsImpl(const ValueFlow::Value& s
91979197 return {};
91989198 if (size.bound == ValueFlow::Value::Bound::Lower)
91999199 return {};
9200+ // Checking for underflow doesnt mean it could be out of bounds
9201+ if (indexValue->intvalue == 0 )
9202+ return {};
92009203 ValueFlow::Value value = inferCondition (" >=" , indexTok, indexValue->intvalue );
92019204 if (!value.isKnown ())
92029205 return {};
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ class TestBufferOverrun : public TestFixture {
195195 TEST_CASE (array_index_68); // #6655
196196 TEST_CASE (array_index_69); // #6370
197197 TEST_CASE (array_index_70); // #11355
198+ TEST_CASE (array_index_71); // #11461
198199 TEST_CASE (array_index_multidim);
199200 TEST_CASE (array_index_switch_in_for);
200201 TEST_CASE (array_index_for_in_for); // FP: #2634
@@ -1912,6 +1913,19 @@ class TestBufferOverrun : public TestFixture {
19121913 ASSERT_EQUALS (" [test.cpp:3]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n " , errout.str ());
19131914 }
19141915
1916+ // #11461
1917+ void array_index_71 ()
1918+ {
1919+ check (" unsigned int f(unsigned int Idx) {\n "
1920+ " if (Idx < 64)\n "
1921+ " return 0;\n "
1922+ " Idx -= 64;\n "
1923+ " int arr[64] = { 0 };\n "
1924+ " return arr[Idx];\n "
1925+ " }\n " );
1926+ ASSERT_EQUALS (" " , errout.str ());
1927+ }
1928+
19151929 void array_index_multidim () {
19161930 check (" void f()\n "
19171931 " {\n "
You can’t perform that action at this time.
0 commit comments