Skip to content

Commit ab6ebb6

Browse files
committed
tests: increase containerOutOfBounds coverage for non-empty containers
Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
1 parent 4e73985 commit ab6ebb6

1 file changed

Lines changed: 23 additions & 33 deletions

File tree

test/teststl.cpp

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ class TestStl : public TestFixture {
176176

177177
TEST_CASE(checkKnownEmptyContainer);
178178
TEST_CASE(checkMutexes);
179-
TEST_CASE(coob_initlist_vector_nonempty_no_fp_regression_20250812);
180-
TEST_CASE(coob_array_initlist_nonempty_no_fp_regression_20250812);
181-
TEST_CASE(coob_vector_pushback_nonempty_no_fp_regression_20250812);
179+
182180

183181
}
184182

@@ -986,6 +984,27 @@ class TestStl : public TestFixture {
986984
" return sv[sv.size()] == '\\0';\n"
987985
"}\n");
988986
ASSERT_EQUALS("[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str());
987+
check("void f(){\n"
988+
" std::vector<double> v = {0.0, 0.1};\n"
989+
" (void)v[0];\n"
990+
"}\n");
991+
ASSERT_EQUALS("", errout_str());
992+
993+
994+
check("void f(){\n"
995+
" std::array<int,2> a = {1,2};\n"
996+
" (void)a[1];\n"
997+
"}\n");
998+
ASSERT_EQUALS("", errout_str());
999+
1000+
1001+
check("void f(){\n"
1002+
" std::vector<int> v;\n"
1003+
" v.push_back(42);\n"
1004+
" (void)v[0];\n"
1005+
"}\n");
1006+
ASSERT_EQUALS("", errout_str());
1007+
9891008
}
9901009
void outOfBoundsIterator() {
9911010
check("int f() {\n"
@@ -7205,36 +7224,7 @@ class TestStl : public TestFixture {
72057224
"}\n");
72067225
ASSERT_EQUALS("", errout_str());
72077226
}
7208-
// Regression guards: non-empty containers must NOT trigger containerOutOfBounds (2025-08-12)
7209-
7210-
7211-
void coob_initlist_vector_nonempty_no_fp_regression_20250812()
7212-
{
7213-
check(
7214-
"#include <vector>\n"
7215-
"void f(){ std::vector<double> v{0.0, 0.1}; (void)v[0]; }\n"
7216-
);
7217-
ASSERT_EQUALS("", errout_str());
7218-
}
7219-
7220-
void coob_array_initlist_nonempty_no_fp_regression_20250812()
7221-
{
7222-
check(
7223-
"#include <array>\n"
7224-
"void f(){ std::array<int,2> a{1,2}; (void)a[1]; }\n"
7225-
);
7226-
ASSERT_EQUALS("", errout_str());
7227-
}
7228-
7229-
void coob_vector_pushback_nonempty_no_fp_regression_20250812()
7230-
{
7231-
check(
7232-
"#include <vector>\n"
7233-
"void f(){ std::vector<int> v; v.push_back(42); (void)v[0]; }\n"
7234-
);
7235-
ASSERT_EQUALS("", errout_str());
7236-
}
7237-
7227+
72387228
};
72397229

72407230
REGISTER_TEST(TestStl)

0 commit comments

Comments
 (0)