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

Method signConversionError

lib/checktype.cpp:286–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286void CheckTypeImpl::signConversionError(const Token *tok, const ValueFlow::Value *negativeValue, const bool constvalue)
287{
288 const std::string expr(tok ? tok->expressionString() : "var");
289
290 std::ostringstream msg;
291 if (tok && tok->isName())
292 msg << "$symbol:" << expr << "\n";
293 if (constvalue)
294 msg << "Expression '" << expr << "' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.";
295 else
296 msg << "Expression '" << expr << "' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.";
297
298 if (!negativeValue)
299 reportError(tok, Severity::warning, "signConversion", msg.str(), CWE195, Certainty::normal);
300 else {
301 ErrorPath errorPath = getErrorPath(tok,negativeValue,"Negative value is converted to an unsigned value");
302 reportError(std::move(errorPath),
303 Severity::warning,
304 getMessageId(*negativeValue, "signConversion").c_str(),
305 msg.str(),
306 CWE195,
307 negativeValue->isInconclusive() ? Certainty::inconclusive : Certainty::normal);
308 }
309}
310
311
312//---------------------------------------------------------------------------

Callers 1

getErrorMessagesMethod · 0.80

Calls 5

getMessageIdFunction · 0.85
reportErrorFunction · 0.70
expressionStringMethod · 0.45
strMethod · 0.45
isInconclusiveMethod · 0.45

Tested by

no test coverage detected