* Add tests for #4336, #4739

* Add test for #8319

* Add test for #6655
This commit is contained in:
chrchr-github 2022-07-13 21:08:30 +02:00 committed by GitHub
parent 21d992cc00
commit b31e40f578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View File

@ -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"

View File

@ -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() {