Change "Array index -1 corresponds with 4294967295..." error message into "Array index -1 is out of bounds"

This commit is contained in:
Reijo Tomperi 2010-04-20 21:44:31 +03:00
parent 47234e2dab
commit 96d66af478
2 changed files with 12 additions and 12 deletions

View File

@ -1268,7 +1268,7 @@ void CheckBufferOverrun::checkSprintfCall(const Token *tok, int size)
void CheckBufferOverrun::negativeIndexError(const Token *tok, long index) void CheckBufferOverrun::negativeIndexError(const Token *tok, long index)
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << "Array index " << index << " corresponds with " << (unsigned long)index << ", which is likely out of bounds"; ostr << "Array index " << index << " is out of bounds";
reportError(tok, Severity::error, "negativeIndex", ostr.str()); reportError(tok, Severity::error, "negativeIndex", ostr.str());
} }

View File

@ -782,7 +782,7 @@ private:
" a[128] = 0;\n" // 128 > CHAR_MAX " a[128] = 0;\n" // 128 > CHAR_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[128]' index 128 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[128]' index 128 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
} }
else // plain char is unsigned else // plain char is unsigned
@ -802,7 +802,7 @@ private:
" a[128] = 0;\n" // 128 > SCHAR_MAX " a[128] = 0;\n" // 128 > SCHAR_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[128]' index 128 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[128]' index 128 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(unsigned char n) {\n" check("void f(unsigned char n) {\n"
" int a[n];\n" // n <= UCHAR_MAX " int a[n];\n" // n <= UCHAR_MAX
@ -810,7 +810,7 @@ private:
" a[256] = 0;\n" // 256 > UCHAR_MAX " a[256] = 0;\n" // 256 > UCHAR_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[256]' index 256 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[256]' index 256 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(short n) {\n" check("void f(short n) {\n"
" int a[n];\n" // n <= SHRT_MAX " int a[n];\n" // n <= SHRT_MAX
@ -818,7 +818,7 @@ private:
" a[32768] = 0;\n" // 32768 > SHRT_MAX " a[32768] = 0;\n" // 32768 > SHRT_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' index 32768 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' index 32768 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(unsigned short n) {\n" check("void f(unsigned short n) {\n"
" int a[n];\n" // n <= USHRT_MAX " int a[n];\n" // n <= USHRT_MAX
@ -826,7 +826,7 @@ private:
" a[65536] = 0;\n" // 65536 > USHRT_MAX " a[65536] = 0;\n" // 65536 > USHRT_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[65536]' index 65536 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[65536]' index 65536 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(signed short n) {\n" check("void f(signed short n) {\n"
" int a[n];\n" // n <= SHRT_MAX " int a[n];\n" // n <= SHRT_MAX
@ -834,7 +834,7 @@ private:
" a[32768] = 0;\n" // 32768 > SHRT_MAX " a[32768] = 0;\n" // 32768 > SHRT_MAX
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' index 32768 out of bounds\n" ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' index 32768 out of bounds\n"
"[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); "[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
if (sizeof(int) == 4) if (sizeof(int) == 4)
{ {
@ -842,19 +842,19 @@ private:
" int a[n];\n" // n <= INT_MAX " int a[n];\n" // n <= INT_MAX
" a[-1] = 0;\n" // negative index " a[-1] = 0;\n" // negative index
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(unsigned int n) {\n" check("void f(unsigned int n) {\n"
" int a[n];\n" // n <= UINT_MAX " int a[n];\n" // n <= UINT_MAX
" a[-1] = 0;\n" // negative index " a[-1] = 0;\n" // negative index
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f(signed int n) {\n" check("void f(signed int n) {\n"
" int a[n];\n" // n <= INT_MAX " int a[n];\n" // n <= INT_MAX
" a[-1] = 0;\n" // negative index " a[-1] = 0;\n" // negative index
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds\n", errout.str());
} }
} }
@ -1014,14 +1014,14 @@ private:
" char data[8];\n" " char data[8];\n"
" data[-1] = 0;\n" " data[-1] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 is out of bounds\n", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"
" char data[8][4];\n" " char data[8][4];\n"
" data[5][-1] = 0;\n" " data[5][-1] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 corresponds with 4294967295, which is likely out of bounds\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 is out of bounds\n", errout.str());
// #1614 - negative index is ok for pointers // #1614 - negative index is ok for pointers
check("void foo(char *p)\n" check("void foo(char *p)\n"