diff --git a/src/checkother.cpp b/src/checkother.cpp index 7d148b49b..ded2ffe46 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -212,8 +212,6 @@ void CheckOther::WarningIf() { if (Token::Match(tok2, ") ; !!else")) { - std::ostringstream ostr; - ostr << _tokenizer->fileLine(tok) << ": Found \"if (condition);\""; _errorLogger->reportErr(ErrorMessage::ifNoAction(_tokenizer, tok)); } break; @@ -357,9 +355,7 @@ void CheckOther::InvalidFunctionUsage() } else if (parlevel == 0 && tok2->varId() == varid) { - std::ostringstream ostr; - ostr << _tokenizer->fileLine(tok2) << ": Overlapping data buffer " << tok2->str(); - _errorLogger->reportErr(ostr.str()); + _errorLogger->reportErr(ErrorMessage::sprintfOverlappingData(_tokenizer, tok2, tok2->str())); break; } } diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index c612bd0c6..edf43e118 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -301,7 +301,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) checkOther.WarningRedundantCode(); // strtol and strtoul usage - if (ErrorMessage::dangerousUsageStrtol(_settings)) + if (ErrorMessage::dangerousUsageStrtol(_settings) || + ErrorMessage::sprintfOverlappingData(_settings)) checkOther.InvalidFunctionUsage(); // Check that all private functions are called. diff --git a/src/errormessage.h b/src/errormessage.h index 47ef4b9ae..b77958f9e 100644 --- a/src/errormessage.h +++ b/src/errormessage.h @@ -192,5 +192,14 @@ public: return s._checkCodingStyle; } + static std::string sprintfOverlappingData(const Tokenizer *tokenizer, const Token *Location, const std::string &varname) + { + return msg1(tokenizer, Location) + "Overlapping data buffer " + varname + ""; + } + static bool sprintfOverlappingData(const Settings &s) + { + return true; + } + }; #endif diff --git a/tools/errmsg.cpp b/tools/errmsg.cpp index 61a424a3d..9d4cb715a 100644 --- a/tools/errmsg.cpp +++ b/tools/errmsg.cpp @@ -80,6 +80,7 @@ int main() err.push_back(Message("redundantIfRemove", Message::STYLE, "Redundant condition. The remove function in the STL will not do anything if element doesn't exist")); err.push_back(Message("dangerousUsageStrtol", 0, "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36")); err.push_back(Message("ifNoAction", Message::STYLE, "Found redundant if condition - 'if (condition);'")); + err.push_back(Message("sprintfOverlappingData", 0, "Overlapping data buffer %1", "varname")); // Generate code.. std::cout << "Generate code.." << std::endl;