Skip to content

Commit 33fde8a

Browse files
Add tests for #1770, #10130 (#4519)
* Add test for #6541, avoid duplicate warning * Add test for #5475 * Fix test * Merge * Add test for #8666 * Fix #11239 checkLibraryCheckType with asm goto() (invalid varid) * Format * Add tests for #1201, #2654 * Fix test * Add test for #6379 * Add tests for #1770, #10130
1 parent 32c7b91 commit 33fde8a

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

test/testbufferoverrun.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,16 @@ class TestBufferOverrun : public TestFixture {
26122612
"ImageSet *ActorSprite::targetCursorImages[2][10];");
26132613
ASSERT_EQUALS("", errout.str());
26142614

2615+
check("int f(const std::size_t s) {\n" // #10130
2616+
" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\n"
2617+
" return (s > sizeof(a)) ? 11 : (int)a[s];\n"
2618+
"}\n"
2619+
"int g() {\n"
2620+
" return f(16);\n"
2621+
"}\n");
2622+
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",
2623+
errout.str());
2624+
26152625
}
26162626

26172627
void array_index_valueflow_pointer() {

test/testfunctions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ class TestFunctions : public TestFixture {
763763

764764
check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }");
765765
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
766+
767+
check("void f() { char a[10] = \"1234567890\"; puts(a); }", "test.c"); // #1770
768+
ASSERT_EQUALS("[test.c:1]: (error) Invalid puts() argument nr 1. A nul-terminated string is required.\n", errout.str());
766769
}
767770

768771
void mathfunctionCall_sqrt() {

0 commit comments

Comments
 (0)