diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index e09c0732b..f6a399b5f 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -192,6 +192,7 @@ private: TEST_CASE(array_index_65); // #11066 TEST_CASE(array_index_66); // #10740 TEST_CASE(array_index_67); // #1596 + TEST_CASE(array_index_68); // #6655 TEST_CASE(array_index_multidim); TEST_CASE(array_index_switch_in_for); TEST_CASE(array_index_for_in_for); // FP: #2634 @@ -1873,6 +1874,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void array_index_68() { // #6655 + check("int ia[10];\n" + "void f(int len) {\n" + " for (int i = 0; i < len; i++)\n" + " ia[i] = 0;\n" + "}\n" + "int g() {\n" + " f(20);\n" + " return 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds.\n", errout.str()); + } + void array_index_multidim() { check("void f()\n" "{\n" diff --git a/test/testother.cpp b/test/testother.cpp index ce26e9c9d..a2f734777 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -65,6 +65,7 @@ private: TEST_CASE(zeroDiv12); TEST_CASE(zeroDiv13); TEST_CASE(zeroDiv14); // #1169 + TEST_CASE(zeroDiv15); // #8319 TEST_CASE(zeroDivCond); // division by zero / useless condition @@ -599,6 +600,16 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Division by zero.\n", errout.str()); } + void zeroDiv15() { // #8319 + check("int f(int i) { return i - 1; }\n" + "int f() {\n" + " const int d = 1;\n" + " const int r = 1 / f(d);\n" + " return r;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout.str()); + } + void zeroDivCond() { check("void f(unsigned int x) {\n" " int y = 17 / x;\n" @@ -4419,6 +4430,23 @@ private: " enum : uint8_t { A, B } var = A;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkP("#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\n" // #4739 + "static unsigned char cmos_hal_read(unsigned index) {\n" + " unsigned short port_0, port_1;\n" + " assert(!verify_cmos_byte_index(index));\n" + " if (index < 128) {\n" + " port_0 = 0x70;\n" + " port_1 = 0x71;\n" + " }\n" + " else {\n" + " port_0 = 0x72;\n" + " port_1 = 0x73;\n" + " }\n" + " OUTB(index, port_0);\n" + " return INB(port_1);\n" + "}\n", "test.c"); + ASSERT_EQUALS("", errout.str()); } @@ -4901,6 +4929,17 @@ private: " do_something();\n" "}"); ASSERT_EQUALS("",errout.str()); + + check("struct AMethodObject {\n" // #4336 + " AMethodObject(double, double, double);\n" + "};\n" + "struct S {\n" + " static void A(double, double, double);\n" + "};\n" + "void S::A(double const a1, double const a2, double const a3) {\n" + " AMethodObject(a1, a2, a3);\n" + "}\n"); + ASSERT_EQUALS("",errout.str()); } void testMisusedScopeObjectDoesNotPickNestedClass() {