| 67 | } |
| 68 | |
| 69 | void 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. |
no test coverage detected