|
29 | 29 | #include "symboldatabase.h" |
30 | 30 | #include "token.h" |
31 | 31 | #include "tokenize.h" |
| 32 | +#include "utils.h" |
32 | 33 | #include "vfvalue.h" |
33 | 34 |
|
34 | 35 | #include "checkother.h" // comparisonNonZeroExpressionLessThanZero and testIfNonZeroExpressionIsPositive |
@@ -243,7 +244,7 @@ void CheckCondition::assignIfError(const Token *tok1, const Token *tok2, const s |
243 | 244 | reportError(locations, |
244 | 245 | Severity::style, |
245 | 246 | "assignIfError", |
246 | | - "Mismatching assignment and comparison, comparison '" + condition + "' is always " + std::string(result ? "true" : "false") + ".", CWE398, Certainty::normal); |
| 247 | + "Mismatching assignment and comparison, comparison '" + condition + "' is always " + std::string(bool_to_string(result)) + ".", CWE398, Certainty::normal); |
247 | 248 | } |
248 | 249 |
|
249 | 250 |
|
@@ -421,8 +422,8 @@ void CheckCondition::comparisonError(const Token *tok, const std::string &bitop, |
421 | 422 | std::ostringstream expression; |
422 | 423 | expression << std::hex << "(X " << bitop << " 0x" << value1 << ") " << op << " 0x" << value2; |
423 | 424 |
|
424 | | - const std::string errmsg("Expression '" + expression.str() + "' is always " + (result?"true":"false") + ".\n" |
425 | | - "The expression '" + expression.str() + "' is always " + (result?"true":"false") + |
| 425 | + const std::string errmsg("Expression '" + expression.str() + "' is always " + bool_to_string(result) + ".\n" |
| 426 | + "The expression '" + expression.str() + "' is always " + bool_to_string(result) + |
426 | 427 | ". Check carefully constants and operators used, these errors might be hard to " |
427 | 428 | "spot sometimes. In case of complex expression it might help to split it to " |
428 | 429 | "separate expressions."); |
@@ -1620,7 +1621,7 @@ void CheckCondition::alwaysTrueFalseError(const Token* tok, const Token* conditi |
1620 | 1621 | const bool alwaysTrue = value && (value->intvalue != 0 || value->isImpossible()); |
1621 | 1622 | const std::string expr = tok ? tok->expressionString() : std::string("x"); |
1622 | 1623 | const std::string conditionStr = (Token::simpleMatch(condition, "return") ? "Return value" : "Condition"); |
1623 | | - const std::string errmsg = conditionStr + " '" + expr + "' is always " + (alwaysTrue ? "true" : "false"); |
| 1624 | + const std::string errmsg = conditionStr + " '" + expr + "' is always " + bool_to_string(alwaysTrue); |
1624 | 1625 | const ErrorPath errorPath = getErrorPath(tok, value, errmsg); |
1625 | 1626 | reportError(errorPath, |
1626 | 1627 | Severity::style, |
@@ -1694,7 +1695,7 @@ void CheckCondition::checkInvalidTestForOverflow() |
1694 | 1695 | result = (cmp == ">" || cmp == ">="); |
1695 | 1696 | else |
1696 | 1697 | result = (cmp == "<" || cmp == "<="); |
1697 | | - invalidTestForOverflow(tok, lhs->valueType(), result ? "true" : "false"); |
| 1698 | + invalidTestForOverflow(tok, lhs->valueType(), bool_to_string(result)); |
1698 | 1699 | continue; |
1699 | 1700 | } |
1700 | 1701 |
|
@@ -2031,7 +2032,7 @@ void CheckCondition::compareValueOutOfTypeRangeError(const Token *comparison, co |
2031 | 2032 | comparison, |
2032 | 2033 | Severity::style, |
2033 | 2034 | "compareValueOutOfTypeRangeError", |
2034 | | - "Comparing expression of type '" + type + "' against value " + std::to_string(value) + ". Condition is always " + (result ? "true" : "false") + ".", |
| 2035 | + "Comparing expression of type '" + type + "' against value " + std::to_string(value) + ". Condition is always " + bool_to_string(result) + ".", |
2035 | 2036 | CWE398, |
2036 | 2037 | Certainty::normal); |
2037 | 2038 | } |
0 commit comments