Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,16 @@ class TestBufferOverrun : public TestFixture {
"ImageSet *ActorSprite::targetCursorImages[2][10];");
ASSERT_EQUALS("", errout.str());

check("int f(const std::size_t s) {\n" // #10130
" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\n"
" return (s > sizeof(a)) ? 11 : (int)a[s];\n"
"}\n"
"int g() {\n"
" return f(16);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds.\n",
errout.str());

}

void array_index_valueflow_pointer() {
Expand Down
3 changes: 3 additions & 0 deletions test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ class TestFunctions : public TestFixture {

check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());

check("void f() { char a[10] = \"1234567890\"; puts(a); }", "test.c"); // #1770
ASSERT_EQUALS("[test.c:1]: (error) Invalid puts() argument nr 1. A nul-terminated string is required.\n", errout.str());
}

void mathfunctionCall_sqrt() {
Expand Down