Improve strncat 3rd parameter usage warning message.
See forum thread: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192
This commit is contained in:
parent
d700f25518
commit
b750a52f6d
|
@ -117,7 +117,10 @@ void CheckBufferOverrun::strncatUsage(const Token *tok)
|
||||||
if (_settings && !_settings->_checkCodingStyle)
|
if (_settings && !_settings->_checkCodingStyle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
reportError(tok, Severity::warning, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
|
reportError(tok, Severity::warning, "strncatUsage",
|
||||||
|
"Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n"
|
||||||
|
"strncat appends at max its 3rd parameter's amount of characters. The safe way to use "
|
||||||
|
"strncat is to calculate remaining space in the buffer and use it as 3rd parameter.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what)
|
void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what)
|
||||||
|
|
|
@ -2112,7 +2112,7 @@ private:
|
||||||
" strncpy(str, a, 10);\n"
|
" strncpy(str, a, 10);\n"
|
||||||
" strncat(str, b, 10);\n"
|
" strncat(str, b, 10);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void strncat2()
|
void strncat2()
|
||||||
|
@ -2122,7 +2122,7 @@ private:
|
||||||
" char str[5];\n"
|
" char str[5];\n"
|
||||||
" strncat(str, a, 5);\n"
|
" strncat(str, a, 5);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void strncat3()
|
void strncat3()
|
||||||
|
|
Loading…
Reference in New Issue