Skip to content
Closed
Changes from all 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
20 changes: 20 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class TestBufferOverrun : public TestFixture
TEST_CASE(array_index_for_break); // FP: for,break
TEST_CASE(array_index_for); // FN: for,if
TEST_CASE(array_index_for_neq); // #2211: Using != in condition
TEST_CASE(array_index_for_printf);

TEST_CASE(buffer_overrun_1);
TEST_CASE(buffer_overrun_2);
Expand Down Expand Up @@ -1366,6 +1367,15 @@ class TestBufferOverrun : public TestFixture
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// check for conditional operator
check("void f() {\n"
" int a[10];\n"
" for (int i = 0; i < 10; i++) {\n"
" i == 0 ? 0 : a[i-1];\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void array_index_for_neq()
Expand All @@ -1380,6 +1390,16 @@ class TestBufferOverrun : public TestFixture
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds: a\n", errout.str());
}

void array_index_for_printf()
{
check("typedef char Str[10];\n"
"void f() {\n"
" Str s;\n"
" printf(\"%.*s %.*s\\n\", sizeof(Str), s, sizeof(Str), s);\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void buffer_overrun_1()
{
check("void f()\n"
Expand Down