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

Method stringLiteralWriteError

lib/checkstring.cpp:69–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void CheckStringImpl::stringLiteralWriteError(const Token *tok, const Token *strValue)
70{
71 std::list<const Token*> callstack{ tok };
72 if (strValue)
73 callstack.push_back(strValue);
74
75 std::string errmsg("Modifying string literal");
76 if (strValue) {
77 std::string s = strValue->str();
78 // 20 is an arbitrary value, the max string length shown in a warning message
79 if (s.size() > 20U)
80 s.replace(17, std::string::npos, "..\"");
81 errmsg += " " + s;
82 }
83 errmsg += " directly or indirectly is undefined behaviour.";
84
85 reportError(callstack, Severity::error, "stringLiteralWrite", errmsg, CWE758, Certainty::normal);
86}
87
88//---------------------------------------------------------------------------
89// Check for string comparison involving two static strings.

Callers 1

getErrorMessagesMethod · 0.80

Calls 5

reportErrorFunction · 0.70
push_backMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected