| 284 | } |
| 285 | |
| 286 | void 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 | //--------------------------------------------------------------------------- |
no test coverage detected