diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5e488e756..50b390961 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2612,6 +2612,16 @@ private: "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() { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 1c361d759..a23e12382 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -763,6 +763,9 @@ private: 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() {