diff --git a/lib/checkother.cpp b/lib/checkother.cpp index aaebf3d6c..02a77540f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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) diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index bfc974fdb..5f0886c43 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -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()); }