MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / sprintfOverlappingDataError

Method sprintfOverlappingDataError

lib/checkstring.cpp:460–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460void CheckStringImpl::sprintfOverlappingDataError(const Token *funcTok, const Token *tok, const std::string &varname)
461{
462 const std::string func = funcTok ? funcTok->str() : "s[n]printf";
463
464 reportError(tok, Severity::error, "sprintfOverlappingData",
465 "$symbol:" + varname + "\n"
466 "Undefined behavior: Variable '$symbol' is used as parameter and destination in " + func + "().\n" +
467 "The variable '$symbol' is used both as a parameter and as destination in " +
468 func + "(). The origin and destination buffers overlap. Quote from glibc (C-library) "
469 "documentation (http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output-Functions): "
470 "\"If copying takes place between objects that overlap as a result of a call "
471 "to sprintf() or snprintf(), the results are undefined.\"", CWE628, Certainty::normal);
472}
473
474void CheckString::runChecks(const Tokenizer &tokenizer, ErrorLogger& errorLogger)
475{

Callers 1

getErrorMessagesMethod · 0.80

Calls 2

reportErrorFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected