Skip to content

Commit 938ad99

Browse files
Add tests for #6925, #11042, #11494 (#4987)
* Add tests for #6925, #11042, #11494 * Format
1 parent 31e714c commit 938ad99

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

test/testbufferoverrun.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5250,6 +5250,16 @@ class TestBufferOverrun : public TestFixture {
52505250
" g(a);\n"
52515251
"}\n");
52525252
ASSERT_EQUALS("", errout.str());
5253+
5254+
ctu("const int a[1] = { 1 };\n" // #11042
5255+
"void g(const int* d) {\n"
5256+
" (void)d[2];\n"
5257+
"}\n"
5258+
"void f() {\n"
5259+
" g(a);\n"
5260+
"}\n");
5261+
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8.\n",
5262+
errout.str());
52535263
}
52545264

52555265
void ctu_variable() {

test/testsimplifytypedef.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,8 +3213,8 @@ class TestSimplifyTypedef : public TestFixture {
32133213
tok(code));
32143214
}
32153215

3216-
void simplifyTypedef140() { // #10798
3217-
{
3216+
void simplifyTypedef140() {
3217+
{ // #10798
32183218
const char code[] = "typedef void (*b)();\n"
32193219
"enum class E { a, b, c };\n";
32203220
ASSERT_EQUALS("enum class E { a , b , c } ;", tok(code));
@@ -3224,6 +3224,11 @@ class TestSimplifyTypedef : public TestFixture {
32243224
"enum class E { A };\n";
32253225
ASSERT_EQUALS("enum class E { A } ;", tok(code));
32263226
}
3227+
{ // #11494
3228+
const char code[] = "typedef struct S {} KEY;\n"
3229+
"class C { enum E { KEY }; };\n";
3230+
ASSERT_EQUALS("struct S { } ; class C { enum E { KEY } ; } ;", tok(code));
3231+
}
32273232
}
32283233

32293234
void simplifyTypedef141() { // #10144

test/teststl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4750,6 +4750,15 @@ class TestStl : public TestFixture {
47504750
" return true;\n"
47514751
"}\n");
47524752
ASSERT_EQUALS("", errout.str());
4753+
4754+
// #6925
4755+
check("void f(const std::string& s, std::string::iterator i) {\n"
4756+
" if (i != s.end() && *(i + 1) == *i) {\n"
4757+
" if (i + 1 != s.end()) {}\n"
4758+
" }\n"
4759+
"}\n");
4760+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n",
4761+
errout.str());
47534762
}
47544763

47554764
void dereferenceInvalidIterator2() {

0 commit comments

Comments
 (0)