@@ -86,7 +86,7 @@ class TestBufferOverrun : public TestFixture {
8686 TEST_CASE (array_index_1);
8787 TEST_CASE (array_index_2);
8888 TEST_CASE (array_index_3);
89- // TODO string TEST_CASE(array_index_4);
89+ TEST_CASE (array_index_4);
9090 TEST_CASE (array_index_6);
9191 TEST_CASE (array_index_7);
9292 TEST_CASE (array_index_11);
@@ -189,6 +189,7 @@ class TestBufferOverrun : public TestFixture {
189189 TEST_CASE (pointer_out_of_bounds_1);
190190 // TODO TEST_CASE(pointer_out_of_bounds_2);
191191 TEST_CASE (pointer_out_of_bounds_3);
192+ TEST_CASE (pointer_out_of_bounds_4);
192193 // TODO TEST_CASE(pointer_out_of_bounds_sub);
193194
194195 // TODO TEST_CASE(strncat1);
@@ -385,13 +386,16 @@ class TestBufferOverrun : public TestFixture {
385386
386387 void array_index_4 () {
387388 check (" char c = \" abc\" [4];" );
388- ASSERT_EQUALS (" [test.cpp:1]: (error) Array index out of bounds: \" abc \" \n" , errout.str ());
389+ ASSERT_EQUALS (" [test.cpp:1]: (error) Array ' \" abc \" [4]' accessed at index 4, which is out of bounds. \n " , errout.str ());
389390
390391 check (" p = &\" abc\" [4];" );
391392 ASSERT_EQUALS (" " , errout.str ());
392393
393394 check (" char c = \"\\ 0abc\" [2];" );
394395 ASSERT_EQUALS (" " , errout.str ());
396+
397+ check (" char c = L\" abc\" [4];" );
398+ ASSERT_EQUALS (" [test.cpp:1]: (error) Array 'L\" abc\" [4]' accessed at index 4, which is out of bounds.\n " , errout.str ());
395399 }
396400
397401 void array_index_3 () {
@@ -2814,6 +2818,29 @@ class TestBufferOverrun : public TestFixture {
28142818 ASSERT_EQUALS (" [test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds.\n " , errout.str ());
28152819 }
28162820
2821+ void pointer_out_of_bounds_4 () {
2822+ check (" const char* f() {\n "
2823+ " g(\" Hello\" + 6);\n "
2824+ " }" );
2825+ ASSERT_EQUALS (" " , errout.str ());
2826+
2827+ check (" const char* f() {\n "
2828+ " g(\" Hello\" + 7);\n "
2829+ " }" );
2830+ ASSERT_EQUALS (" [test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic '\" Hello\" +7' is out of bounds.\n " , errout.str ());
2831+
2832+ check (" const char16_t* f() {\n "
2833+ " g(u\" Hello\" + 6);\n "
2834+ " }" );
2835+ ASSERT_EQUALS (" " , errout.str ());
2836+
2837+ check (" const char16_t* f() {\n "
2838+ " g(u\" Hello\" + 7);\n "
2839+ " }" );
2840+ ASSERT_EQUALS (" [test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic 'u\" Hello\" +7' is out of bounds.\n " , errout.str ());
2841+ }
2842+
2843+
28172844 void pointer_out_of_bounds_sub () {
28182845 check (" void f() {\n "
28192846 " char x[10];\n "
0 commit comments