Fixed #2979 (Improve message: using char as array index)
This commit is contained in:
parent
e2367b4149
commit
8a6a999f09
|
@ -3627,13 +3627,10 @@ void CheckOther::charArrayIndexError(const Token *tok)
|
|||
reportError(tok,
|
||||
Severity::warning,
|
||||
"charArrayIndex",
|
||||
"When using a char variable as array index, sign extension will mean buffer overflow.\n"
|
||||
"When using a char variable as array index, sign extension will cause buffer overflows. For example:\n"
|
||||
" char c = 0x80;\n"
|
||||
" char buf[512];\n"
|
||||
" buf[c] = 13; // buffer overflow, index must be a value between 0 and 511.\n"
|
||||
" printf(\"%i\", buf[0x80]);\n"
|
||||
"There is a big chance that the value that is printed won't be 13.");
|
||||
"Using char type as array index\n"
|
||||
"Using signed char type as array index. If the value "
|
||||
"can be greater than 127 there will be a buffer overflow "
|
||||
"(because of sign extension).");
|
||||
}
|
||||
|
||||
void CheckOther::charBitOpError(const Token *tok)
|
||||
|
|
|
@ -77,20 +77,20 @@ private:
|
|||
" char ch = 0x80;\n"
|
||||
" buf[ch] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) When using a char variable as array index, sign extension will mean buffer overflow.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Using char type as array index\n", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" signed char ch = 0x80;\n"
|
||||
" buf[ch] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) When using a char variable as array index, sign extension will mean buffer overflow.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Using char type as array index\n", errout.str());
|
||||
|
||||
check("void foo(char ch)\n"
|
||||
"{\n"
|
||||
" buf[ch] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) When using a char variable as array index, sign extension will mean buffer overflow.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Using char type as array index\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue