* Add tests for #6925, #11042, #11494 * Format * Add tests for # 6561, #6619, #7475, * Add tests for #8075, #11608, #11635
This commit is contained in:
parent
5a4e43760e
commit
6e5375f7b7
|
@ -199,6 +199,7 @@ private:
|
|||
TEST_CASE(array_index_negative6); // #11349
|
||||
TEST_CASE(array_index_negative7); // #5685
|
||||
TEST_CASE(array_index_negative8); // #11651
|
||||
TEST_CASE(array_index_negative9);
|
||||
TEST_CASE(array_index_for_decr);
|
||||
TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586
|
||||
TEST_CASE(array_index_for_continue); // for,continue
|
||||
|
@ -2288,6 +2289,21 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #8075
|
||||
void array_index_negative9()
|
||||
{
|
||||
check("int g(int i) {\n"
|
||||
" if (i < 10)\n"
|
||||
" return -1;\n"
|
||||
" return 0;\n"
|
||||
"}\n"
|
||||
"void f() {\n"
|
||||
" int a[] = { 1, 2, 3 };\n"
|
||||
" printf(\"%d\\n\", a[g(4)]);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Array 'a[3]' accessed at index -1, which is out of bounds.\n", errout.str());
|
||||
}
|
||||
|
||||
void array_index_for_decr() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
|
|
@ -3541,6 +3541,18 @@ private:
|
|||
" *ptr++ = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #11635
|
||||
check("void f(char *cons, int rlen, int pos) {\n"
|
||||
" int i;\n"
|
||||
" char* cp1;\n"
|
||||
" for (cp1 = &cons[pos], i = 1; i < rlen; cp1--)\n"
|
||||
" if (*cp1 == '*')\n"
|
||||
" continue;\n"
|
||||
" else\n"
|
||||
" i++;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointerDelete() {
|
||||
|
|
|
@ -5989,6 +5989,15 @@ private:
|
|||
" printf(\"%d\", s.a);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s.a\n", errout.str());
|
||||
|
||||
valueFlowUninit("void f(char* src) {\n" // #11608
|
||||
" char envar[64], *cp, c;\n"
|
||||
" for (src += 2, cp = envar; (c = *src) != '\\0'; src++)\n"
|
||||
" *cp++ = c;\n"
|
||||
" if (cp != envar)\n"
|
||||
" if ((cp = getenv(envar)) != NULL) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
|
||||
|
|
Loading…
Reference in New Issue