* Add tests for #6925, #11042, #11494

* Format

* Add tests for # 6561, #6619, #7475,

* Add tests for #8075, #11608, #11635
This commit is contained in:
chrchr-github 2023-04-21 16:09:52 +02:00 committed by GitHub
parent 5a4e43760e
commit 6e5375f7b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

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

View File

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

View File

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