diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 72e37233a..864ec4fde 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -59,8 +59,8 @@ void CheckOther::incrementBooleanError(const Token *tok) tok, Severity::style, "incrementboolean", - "The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n" - "The operand of a postfix increment operator may be of type bool but it is deprecated by C++ Standard (Annex D-1) and the operand is always set to true." + "Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n" + "The operand of a postfix increment operator may be of type bool but it is deprecated by C++ Standard (Annex D-1) and the operand is always set to true. You should assign it the value 'true' instead." ); } @@ -133,9 +133,9 @@ void CheckOther::clarifyCalculationError(const Token *tok, const std::string &op reportError(tok, Severity::style, "clarifyCalculation", - "Clarify calculation precedence for " + op + " and ?\n" + "Clarify calculation precedence for '" + op + "' and '?'.\n" "Suspicious calculation. Please use parentheses to clarify the code. " - "The code " + calc + " should be written as either " + s1 + " or " + s2 + "."); + "The code '" + calc + "' should be written as either '" + s1 + "' or '" + s2 + "'."); } //--------------------------------------------------------------------------- @@ -212,15 +212,15 @@ void CheckOther::clarifyConditionError(const Token *tok, bool assign, bool boolo std::string errmsg; if (assign) - errmsg = "Suspicious condition (assignment+comparison), it can be clarified with parentheses"; + errmsg = "Suspicious condition (assignment + comparison); Clarify expression with parentheses."; else if (boolop) - errmsg = "Boolean result is used in bitwise operation. Clarify expression with parentheses\n" - "Suspicious expression. Boolean result is used in bitwise operation. The ! operator " + errmsg = "Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" + "Suspicious expression. Boolean result is used in bitwise operation. The operator '!'" "and the comparison operators have higher precedence than bitwise operators. " "It is recommended that the expression is clarified with parentheses."; else - errmsg = "Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n" + errmsg = "Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n" "Suspicious condition. Comparison operators have higher precedence than bitwise operators. Please clarify the condition with parentheses."; reportError(tok, @@ -306,7 +306,7 @@ void CheckOther::checkBitwiseOnBoolean() void CheckOther::bitwiseOnBooleanError(const Token *tok, const std::string &varname, const std::string &op) { reportError(tok, Severity::style, "bitwiseOnBoolean", - "Boolean variable '" + varname + "' is used in bitwise operation. Did you mean " + op + " ?", true); + "Boolean variable '" + varname + "' is used in bitwise operation. Did you mean '" + op + "'?", true); } void CheckOther::checkSuspiciousSemicolon() @@ -457,11 +457,11 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr { if (to == "integer") { // If we cast something to int*, this can be useful to play with its binary data representation if (!inconclusive) - reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to integer* is not portable due to different binary data representations on different platforms"); + reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to integer* is not portable due to different binary data representations on different platforms."); else - reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* might be not portable due to different binary data representations on different platforms", true); + reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* is not portable due to different binary data representations on different platforms.", true); } else - reportError(tok, Severity::warning, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation"); + reportError(tok, Severity::warning, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation."); } //--------------------------------------------------------------------------- @@ -483,11 +483,10 @@ void CheckOther::checkSizeofForNumericParameter() void CheckOther::sizeofForNumericParameterError(const Token *tok) { reportError(tok, Severity::warning, - "sizeofwithnumericparameter", "Using sizeof with a numeric constant as function " - "argument might not be what you intended.\n" - "It is unusual to use constant value with sizeof. For example, sizeof(10)" - " returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 10. sizeof('A')" - " and sizeof(char) can return different results."); + "sizeofwithnumericparameter", "Suspicious usage of 'sizeof' with a numeric constant as parameter.\n" + "It is unusual to use a constant value with sizeof. For example, 'sizeof(10)'" + " returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 10. 'sizeof('A')'" + " and 'sizeof(char)' can return different results."); } //--------------------------------------------------------------------------- @@ -515,16 +514,15 @@ void CheckOther::checkSizeofForArrayParameter() void CheckOther::sizeofForArrayParameterError(const Token *tok) { reportError(tok, Severity::error, - "sizeofwithsilentarraypointer", "Using sizeof for array given as function argument " - "returns the size of pointer.\n" - "Giving array as function parameter and then using sizeof-operator for the array " - "argument. In this case the sizeof-operator returns the size of pointer (in the " - "system). It does not return the size of the whole array in bytes as might be " + "sizeofwithsilentarraypointer", "Using 'sizeof' on array given as function argument " + "returns size of a pointer.\n" + "Using 'sizeof' for array given as function argument returns the size of a pointer. " + "It does not return the size of the whole array in bytes as might be " "expected. For example, this code:\n" " int f(char a[100]) {\n" " return sizeof(a);\n" " }\n" - " returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 100 (the " + "returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 100 (the " "size of the array in bytes)." ); } @@ -612,10 +610,10 @@ void CheckOther::checkSizeofForPointerSize() void CheckOther::sizeofForPointerError(const Token *tok, const std::string &varname) { reportError(tok, Severity::warning, "pointerSize", - "Using size of pointer " + varname + " instead of size of its data.\n" - "Using size of pointer " + varname + " instead of size of its data. " + "Size of pointer '" + varname + "' used instead of size of its data.\n" + "Size of pointer '" + varname + "' used instead of size of its data. " "This is likely to lead to a buffer overflow. You probably intend to " - "write sizeof(*" + varname + ")", true); + "write 'sizeof(*" + varname + ")'.", true); } //--------------------------------------------------------------------------- @@ -749,7 +747,7 @@ void CheckOther::redundantCopyInSwitchError(const Token *tok1, const Token* tok2 callstack.push_back(tok1); callstack.push_back(tok2); reportError(callstack, Severity::warning, "redundantCopyInSwitch", - "Buffer '" + var + "' is being written before its old content has been used. This might indicate a missing 'break;'."); + "Buffer '" + var + "' is being written before its old content has been used. 'break;' missing?"); } void CheckOther::redundantAssignmentError(const Token *tok1, const Token* tok2, const std::string& var) @@ -767,7 +765,7 @@ void CheckOther::redundantAssignmentInSwitchError(const Token *tok1, const Token callstack.push_back(tok1); callstack.push_back(tok2); reportError(callstack, Severity::warning, "redundantAssignInSwitch", - "Variable '" + var + "' is reassigned a value before the old one has been used. This might indicate a missing 'break;'."); + "Variable '" + var + "' is reassigned a value before the old one has been used. 'break;' missing?"); } @@ -875,7 +873,7 @@ void CheckOther::checkRedundantAssignmentInSwitch() void CheckOther::redundantBitwiseOperationInSwitchError(const Token *tok, const std::string &varname) { reportError(tok, Severity::warning, - "redundantBitwiseOperationInSwitch", "Redundant bitwise operation on \"" + varname + "\" in switch"); + "redundantBitwiseOperationInSwitch", "Redundant bitwise operation on '" + varname + "' in 'switch' statement. 'break;' missing?"); } @@ -1011,7 +1009,7 @@ void CheckOther::checkSwitchCaseFallThrough() void CheckOther::switchCaseFallThrough(const Token *tok) { reportError(tok, Severity::style, - "switchCaseFallThrough", "Switch falls through case without comment"); + "switchCaseFallThrough", "Switch falls through case without comment. 'break;' missing?"); } //--------------------------------------------------------------------------- @@ -1066,7 +1064,7 @@ void CheckOther::checkSelfAssignment() void CheckOther::selfAssignmentError(const Token *tok, const std::string &varname) { reportError(tok, Severity::warning, - "selfAssignment", "Redundant assignment of \"" + varname + "\" to itself"); + "selfAssignment", "Redundant assignment of '" + varname + "' to itself."); } //--------------------------------------------------------------------------- @@ -1101,8 +1099,8 @@ void CheckOther::assignmentInAssertError(const Token *tok, const std::string &va "assignmentInAssert", "Assert statement modifies '" + varname + "'.\n" "Variable '" + varname + "' is modified insert assert statement. " "Assert statements are removed from release builds so the code inside " - "assert statement is not run. If the code is needed also in release " - "builds this is a bug."); + "assert statement is not executed. If the code is needed also in release " + "builds, this is a bug."); } //--------------------------------------------------------------------------- @@ -1395,6 +1393,7 @@ void CheckOther::invalidFunctionUsage() if (!Token::Match(tok, "strtol|strtoul (")) continue; + const std::string& funcname = tok->str(); tok = tok->tokAt(2); // Locate the third parameter of the function call.. for (int i = 0; i < 2 && tok; i++) @@ -1403,7 +1402,7 @@ void CheckOther::invalidFunctionUsage() if (Token::Match(tok, "%num% )")) { const MathLib::bigint radix = MathLib::toLongNumber(tok->str()); if (!(radix == 0 || (radix >= 2 && radix <= 36))) { - dangerousUsageStrtolError(tok); + dangerousUsageStrtolError(tok, funcname); } } else break; @@ -1439,27 +1438,27 @@ void CheckOther::invalidFunctionUsage() // is any source buffer overlapping the target buffer? do { if (Token::Match(tok2, "%varid% [,)]", varid)) { - sprintfOverlappingDataError(tok2->next(), tok2->next()->str()); + sprintfOverlappingDataError(tok2, tok2->str()); break; } } while (NULL != (tok2 = tok2->nextArgument())); } } -void CheckOther::dangerousUsageStrtolError(const Token *tok) +void CheckOther::dangerousUsageStrtolError(const Token *tok, const std::string& funcname) { - reportError(tok, Severity::error, "dangerousUsageStrtol", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36"); + reportError(tok, Severity::error, "dangerousUsageStrtol", "Invalid radix in call to " + funcname + "(). It must be 0 or 2-36."); } void CheckOther::sprintfOverlappingDataError(const Token *tok, const std::string &varname) { reportError(tok, Severity::error, "sprintfOverlappingData", - "Undefined behavior: variable is used as parameter and destination in s[n]printf().\n" - "The variable '" + varname + "' is used both as a parameter and as a destination in " + "Undefined behavior: Variable '" + varname + "' is used as parameter and destination in s[n]printf().\n" + "The variable '" + varname + "' is used both as a parameter and as destination in " "s[n]printf(). The origin and destination buffers overlap. Quote from glibc (C-library) " "documentation (http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output-Functions): " - "'If copying takes place between objects that overlap as a result of a call " - "to sprintf() or snprintf(), the results are undefined.'"); + "\"If copying takes place between objects that overlap as a result of a call " + "to sprintf() or snprintf(), the results are undefined.\""); } //--------------------------------------------------------------------------- @@ -1526,23 +1525,23 @@ void CheckOther::comparisonOfBoolWithIntError(const Token *tok, const std::strin { if (n0o1) reportError(tok, Severity::warning, "comparisonOfBoolWithInt", - "Comparison of a boolean with an integer that is neither 1 nor 0\n" - "The expression \"" + expression + "\" is of type 'bool' " - "and it is compared against a integer value that is " + "Comparison of a boolean with an integer that is neither 1 nor 0.\n" + "The expression '" + expression + "' is of type 'bool' " + "and it is compared against an integer value that is " "neither 1 nor 0."); else reportError(tok, Severity::warning, "comparisonOfBoolWithInt", - "Comparison of a boolean with an integer\n" - "The expression \"" + expression + "\" is of type 'bool' " - "and it is compared against a integer value."); + "Comparison of a boolean with an integer.\n" + "The expression '" + expression + "' is of type 'bool' " + "and it is compared against an integer value."); } void CheckOther::comparisonOfBoolWithInvalidComparator(const Token *tok, const std::string &expression) { reportError(tok, Severity::warning, "comparisonOfBoolWithInvalidComparator", - "Comparison of a boolean value using relational (<, >, <= or >=) operator.\n" - "The expression \"" + expression + "\" is of type 'bool' " - "and result is of type 'bool'. Comparing 'bool' value using relational (<, >, <= or >=)" + "Comparison of a boolean value using relational operator (<, >, <= or >=).\n" + "The result of the expression '" + expression + "' is of type 'bool'. " + "Comparing 'bool' value using relational (<, >, <= or >=)" " operator could cause unexpected results."); } @@ -1624,7 +1623,8 @@ void CheckOther::duplicateBreakError(const Token *tok, bool inconclusive) { reportError(tok, Severity::style, "duplicateBreak", "Consecutive return, break, continue, goto or throw statements are unnecessary.\n" - "The second of the two statements can never be executed, and so should be removed.", inconclusive); + "Consecutive return, break, continue, goto or throw statements are unnecessary. " + "The second statement can never be executed, and so should be removed.", inconclusive); } void CheckOther::unreachableCodeError(const Token *tok, bool inconclusive) @@ -1704,7 +1704,7 @@ void CheckOther::checkMemsetZeroBytes() void CheckOther::memsetZeroBytesError(const Token *tok, const std::string &varname) { - const std::string summary("memset() called to fill 0 bytes of \'" + varname + "\'"); + const std::string summary("memset() called to fill 0 bytes of '" + varname + "'."); const std::string verbose(summary + ". Second and third arguments might be inverted."); reportError(tok, Severity::warning, "memsetZeroBytes", summary + "\n" + verbose); } @@ -1845,17 +1845,17 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname reportError(tok, Severity::style, "variableScope", - "The scope of the variable '" + varname + "' can be reduced\n" - "The scope of the variable '" + varname + "' can be reduced. Warning: It can be unsafe " - "to fix this message. Be careful. Especially when there are inner loops. Here is an " + "The scope of the variable '" + varname + "' can be reduced.\n" + "The scope of the variable '" + varname + "' can be reduced. Warning: Be careful " + "when fixing this message, especially when there are inner loops. Here is an " "example where cppcheck will write that the scope for 'i' can be reduced:\n" "void f(int x)\n" "{\n" " int i = 0;\n" " if (x) {\n" - " // it's safe to move 'int i = 0' here\n" + " // it's safe to move 'int i = 0;' here\n" " for (int n = 0; n < 10; ++n) {\n" - " // it is possible but not safe to move 'int i = 0' here\n" + " // it is possible but not safe to move 'int i = 0;' here\n" " do_something(&i);\n" " }\n" " }\n" @@ -1898,7 +1898,7 @@ void CheckOther::passedByValueError(const Token *tok, const std::string &parname { reportError(tok, Severity::performance, "passedByValue", "Function parameter '" + parname + "' should be passed by reference.\n" - "Parameter '" + parname + "' is passed as a value. It could be passed " + "Parameter '" + parname + "' is passed by value. It could be passed " "as a (const) reference which is usually faster and recommended in C++."); } @@ -1972,10 +1972,10 @@ void CheckOther::charArrayIndexError(const Token *tok) reportError(tok, Severity::warning, "charArrayIndex", - "Using char type as array index\n" - "Using signed char type as array index. If the value " - "can be greater than 127 there will be a buffer overflow " - "(because of sign extension)."); + "Signed 'char' type used as array index.\n" + "Signed 'char' type used as array index. If the value " + "can be greater than 127 there will be a buffer underflow " + "because of sign extension."); } void CheckOther::charBitOpError(const Token *tok) @@ -1983,13 +1983,13 @@ void CheckOther::charBitOpError(const Token *tok) reportError(tok, Severity::warning, "charBitOp", - "When using char variables in bit operations, sign extension can generate unexpected results.\n" - "When using char variables in bit operations, sign extension can generate unexpected results. For example:\n" + "When using 'char' variables in bit operations, sign extension can generate unexpected results.\n" + "When using 'char' variables in bit operations, sign extension can generate unexpected results. For example:\n" " char c = 0x80;\n" " int i = 0 | c;\n" " if (i & 0x8000)\n" " printf(\"not expected\");\n" - "The 'not expected' will be printed on the screen."); + "The \"not expected\" will be printed on the screen."); } //--------------------------------------------------------------------------- @@ -2036,7 +2036,7 @@ void CheckOther::checkIncompleteStatement() void CheckOther::constStatementError(const Token *tok, const std::string &type) { - reportError(tok, Severity::warning, "constStatement", "Redundant code: Found a statement that begins with " + type + " constant"); + reportError(tok, Severity::warning, "constStatement", "Redundant code: Found a statement that begins with " + type + " constant."); } //--------------------------------------------------------------------------- @@ -2068,7 +2068,7 @@ void CheckOther::strPlusChar() void CheckOther::strPlusCharError(const Token *tok) { - reportError(tok, Severity::error, "strPlusChar", "Unusual pointer arithmetic"); + reportError(tok, Severity::error, "strPlusChar", "Unusual pointer arithmetic. A value of type 'char' is added to a string literal."); } //--------------------------------------------------------------------------- @@ -2090,7 +2090,7 @@ void CheckOther::checkZeroDivision() void CheckOther::zerodivError(const Token *tok) { - reportError(tok, Severity::error, "zerodiv", "Division by zero"); + reportError(tok, Severity::error, "zerodiv", "Division by zero."); } //--------------------------------------------------------------------------- @@ -2158,11 +2158,11 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP { if (tok) { if (numParam == 1) - reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->strAt(2) + " to " + tok->str() + "() leads to undefined result"); + reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->strAt(2) + " to " + tok->str() + "() leads to undefined result."); else if (numParam == 2) - reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->strAt(2) + " and " + tok->strAt(4) + " to " + tok->str() + "() leads to undefined result"); + reportError(tok, Severity::error, "wrongmathcall", "Passing values " + tok->strAt(2) + " and " + tok->strAt(4) + " to " + tok->str() + "() leads to undefined result."); } else - reportError(tok, Severity::error, "wrongmathcall", "Passing value " " to " "() leads to undefined result"); + reportError(tok, Severity::error, "wrongmathcall", "Passing value '#' to #() leads to undefined result."); } //--------------------------------------------------------------------------- @@ -2179,7 +2179,7 @@ void CheckOther::checkCCTypeFunctions() } void CheckOther::cctypefunctionCallError(const Token *tok, const std::string &functionName, const std::string &value) { - reportError(tok, Severity::error, "wrongcctypecall", "Passing value " + value + " to " + functionName + "() cause undefined behavior, which may lead to a crash"); + reportError(tok, Severity::error, "wrongcctypecall", "Passing value " + value + " to " + functionName + "() causes undefined behavior which may lead to a crash."); } //--------------------------------------------------------------------------- @@ -2236,7 +2236,7 @@ void CheckOther::checkMisusedScopedObject() void CheckOther::misusedScopeObjectError(const Token *tok, const std::string& varname) { reportError(tok, Severity::error, - "unusedScopedObject", "Instance of \"" + varname + "\" object destroyed immediately."); + "unusedScopedObject", "Instance of '" + varname + "' object is destroyed immediately."); } //--------------------------------------------------------------------------- @@ -2251,13 +2251,13 @@ void CheckOther::checkIncorrectStringCompare() MathLib::bigint clen = MathLib::toLongNumber(tok->strAt(5)); std::size_t slen = Token::getStrLength(tok->tokAt(8)); if (clen != (int)slen) { - incorrectStringCompareError(tok->next(), "substr", tok->strAt(8), tok->strAt(5)); + incorrectStringCompareError(tok->next(), "substr", tok->strAt(8)); } } else if (Token::Match(tok, "%str% ==|!= %var% . substr ( %any% , %num% )")) { MathLib::bigint clen = MathLib::toLongNumber(tok->strAt(8)); std::size_t slen = Token::getStrLength(tok); if (clen != (int)slen) { - incorrectStringCompareError(tok->next(), "substr", tok->str(), tok->strAt(8)); + incorrectStringCompareError(tok->next(), "substr", tok->str()); } } else if (Token::Match(tok, "&&|%oror% %str% &&|%oror%|)")) { // assert(condition && "debug message") would be considered a fp. @@ -2273,14 +2273,14 @@ void CheckOther::checkIncorrectStringCompare() } } -void CheckOther::incorrectStringCompareError(const Token *tok, const std::string& func, const std::string &string, const std::string &len) +void CheckOther::incorrectStringCompareError(const Token *tok, const std::string& func, const std::string &string) { - reportError(tok, Severity::warning, "incorrectStringCompare", "String literal " + string + " doesn't match length argument for " + func + "(" + len + ")."); + reportError(tok, Severity::warning, "incorrectStringCompare", "String literal " + string + " doesn't match length argument for " + func + "()."); } void CheckOther::incorrectStringBooleanError(const Token *tok, const std::string& string) { - reportError(tok, Severity::warning, "incorrectStringBooleanError", "A boolean comparison with the string literal " + string + " is always true."); + reportError(tok, Severity::warning, "incorrectStringBooleanError", "Conversion of string literal " + string + " to bool always evaluates to true."); } //----------------------------------------------------------------------------- @@ -2364,8 +2364,8 @@ void CheckOther::duplicateIfError(const Token *tok1, const Token *tok2) toks.push_back(tok2); toks.push_back(tok1); - reportError(toks, Severity::style, "duplicateIf", "Found duplicate if expressions.\n" - "Finding the same expression more than once is suspicious and might indicate " + reportError(toks, Severity::style, "duplicateIf", "Duplicate conditions in 'if' and related 'else if'.\n" + "Duplicate conditions in 'if' and related 'else if'. This is suspicious and might indicate " "a cut and paste or logic error. Please examine this code carefully to determine " "if it is correct."); } @@ -2402,6 +2402,18 @@ void CheckOther::checkDuplicateBranch() } } +void CheckOther::duplicateBranchError(const Token *tok1, const Token *tok2) +{ + std::list toks; + toks.push_back(tok2); + toks.push_back(tok1); + + reportError(toks, Severity::style, "duplicateBranch", "Found duplicate branches for 'if' and 'else'.\n" + "Finding the same code in an 'if' and related 'else' branch is suspicious and " + "might indicate a cut and paste or logic error. Please examine this code " + "carefully to determine if it is correct."); +} + //----------------------------------------------------------------------------- // Check for a free() of an invalid address @@ -2571,18 +2583,6 @@ void CheckOther::doubleCloseDirError(const Token *tok, const std::string &varnam reportError(tok, Severity::error, "doubleCloseDir", "Directory handle '" + varname +"' closed twice."); } -void CheckOther::duplicateBranchError(const Token *tok1, const Token *tok2) -{ - std::list toks; - toks.push_back(tok2); - toks.push_back(tok1); - - reportError(toks, Severity::style, "duplicateBranch", "Found duplicate branches for if and else.\n" - "Finding the same code for an if branch and an else branch is suspicious and " - "might indicate a cut and paste or logic error. Please examine this code " - "carefully to determine if it is correct."); -} - namespace { struct ExpressionTokens { const Token *start; @@ -3051,7 +3051,7 @@ void CheckOther::sizeofsizeof() void CheckOther::sizeofsizeofError(const Token *tok) { reportError(tok, Severity::warning, - "sizeofsizeof", "Calling sizeof for 'sizeof'.\n" + "sizeofsizeof", "Calling 'sizeof' on 'sizeof'.\n" "Calling sizeof for 'sizeof looks like a suspicious code and " "most likely there should be just one 'sizeof'. The current " "code is equivalent to 'sizeof(size_t)'"); @@ -3082,7 +3082,7 @@ void CheckOther::sizeofCalculation() void CheckOther::sizeofCalculationError(const Token *tok, bool inconclusive) { reportError(tok, Severity::warning, - "sizeofCalculation", "Found calculation inside sizeof()", inconclusive); + "sizeofCalculation", "Found calculation inside sizeof().", inconclusive); } //----------------------------------------------------------------------------- @@ -3105,7 +3105,7 @@ void CheckOther::checkAssignBoolToPointer() void CheckOther::assignBoolToPointerError(const Token *tok) { reportError(tok, Severity::error, "assignBoolToPointer", - "Assigning bool value to pointer (converting bool value to address)"); + "Boolean value assigned to pointer."); } //----------------------------------------------------------------------------- @@ -3232,7 +3232,7 @@ void CheckOther::unsignedLessThanZeroError(const Token *tok, const std::string & "Checking if unsigned variable '" + varname + "' is less than zero. An unsigned " "variable will never be negative so it is either pointless or an error to check if it is. " "It's not known if the used constant is a template parameter or not and therefore " - "this message might be a false warning", true); + "this message might be a false warning.", true); } else { reportError(tok, Severity::style, "unsignedLessThanZero", "Checking if unsigned variable '" + varname + "' is less than zero.\n" @@ -3251,13 +3251,13 @@ void CheckOther::unsignedPositiveError(const Token *tok, const std::string &varn { if (inconclusive) { reportError(tok, Severity::style, "unsignedPositive", - "An unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it. This might be a false warning.\n" - "An unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it. " + "Unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it.\n" + "The unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it. " "It's not known if the used constant is a " "template parameter or not and therefore this message might be a false warning", true); } else { reportError(tok, Severity::style, "unsignedPositive", - "An unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it."); + "Unsigned variable '" + varname + "' can't be negative so it is unnecessary to test it."); } } @@ -3312,8 +3312,9 @@ void CheckOther::checkRedundantCopy() void CheckOther::redundantCopyError(const Token *tok,const std::string& varname) { reportError(tok, Severity::performance,"redundantCopyLocalConst", - "Use const reference for "+varname+" to avoid unnecessary data copying.\n" - "The const "+varname+" gets a copy of the data since const reference is not used. You can avoid the unnecessary data copying by converting "+varname+" to const reference instead of just const."); + "Use const reference for '" + varname + "' to avoid unnecessary data copying.\n" + "The const variable '"+varname+"' is assigned a copy of the data. You can avoid " + "the unnecessary data copying by converting '" + varname + "' to const reference."); } //--------------------------------------------------------------------------- @@ -3497,5 +3498,5 @@ void CheckOther::avoidDeadEndInNestedIfs() void CheckOther::warningDeadCode(const Token *tok) { - reportError(tok, Severity::warning, "redundantOperationIn", "There are opposite condition checks in your nested-if block, which leads to a dead code block", true); + reportError(tok, Severity::warning, "redundantOperationIn", "Opposite conditions in nested 'if' blocks lead to a dead code block.", true); } diff --git a/lib/checkother.h b/lib/checkother.h index 346f23131..c08d46b23 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -279,7 +279,7 @@ private: void sizeofCalculationError(const Token *tok, bool inconclusive); void cstyleCastError(const Token *tok); void invalidPointerCastError(const Token* tok, const std::string& from, const std::string& to, bool inconclusive); - void dangerousUsageStrtolError(const Token *tok); + void dangerousUsageStrtolError(const Token *tok, const std::string& funcname); void sprintfOverlappingDataError(const Token *tok, const std::string &varname); void udivError(const Token *tok, bool inconclusive); void passedByValueError(const Token *tok, const std::string &parname); @@ -306,7 +306,7 @@ private: void sizeofForArrayParameterError(const Token *tok); void sizeofForPointerError(const Token *tok, const std::string &varname); void sizeofForNumericParameterError(const Token *tok); - void incorrectStringCompareError(const Token *tok, const std::string& func, const std::string &string, const std::string &len); + void incorrectStringCompareError(const Token *tok, const std::string& func, const std::string &string); void incorrectStringBooleanError(const Token *tok, const std::string& string); void incrementBooleanError(const Token *tok); void comparisonOfBoolWithIntError(const Token *tok, const std::string &expression, bool n0o1); @@ -358,7 +358,7 @@ private: // style/warning c.warningDeadCode(0); c.cstyleCastError(0); - c.dangerousUsageStrtolError(0); + c.dangerousUsageStrtolError(0, "strtol"); c.passedByValueError(0, "parametername"); c.constStatementError(0, "type"); c.charArrayIndexError(0); @@ -378,7 +378,7 @@ private: c.clarifyCalculationError(0, "+"); c.clarifyConditionError(0, true, false); c.clarifyStatementError(0); - c.incorrectStringCompareError(0, "substr", "\"Hello World\"", "12"); + c.incorrectStringCompareError(0, "substr", "\"Hello World\""); c.suspiciousStringCompareError(0, "foo"); c.incorrectStringBooleanError(0, "\"Hello World\""); c.incrementBooleanError(0); diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 7f985e3f0..f17824242 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -77,7 +77,7 @@ private: " char ch = 0x80;\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Using char type as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Signed 'char' type used as array index.\n", errout.str()); check("int buf[256];\n" "void foo()\n" @@ -85,14 +85,14 @@ private: " signed char ch = 0x80;\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Using char type as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Signed 'char' type used as array index.\n", errout.str()); check("int buf[256];\n" "void foo(char ch)\n" "{\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Using char type as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Signed 'char' type used as array index.\n", errout.str()); check("void foo(const char str[])\n" "{\n" @@ -120,7 +120,7 @@ private: "void bar(char c) {\n" " buf[c] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Using char type as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Signed 'char' type used as array index.\n", errout.str()); check("char buf[0x80];\n" "void bar(char c) {\n" @@ -141,7 +141,7 @@ private: " char ch;\n" " result = a | ch;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) When using char variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); } void bitop2() { @@ -157,7 +157,7 @@ private: check("void f(int& i, char& c) {\n" " i &= c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (warning) When using char variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); } void return1() { @@ -195,7 +195,7 @@ private: " ret |= *p;\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) When using char variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); // fixed code check("void f(char *p) {\n" diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 5bd086cab..bd05e85e6 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -90,7 +90,7 @@ private: " \"abc\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant.\n", errout.str()); } void test3() { @@ -122,7 +122,7 @@ private: " 50;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str()); } void test_numeric() { diff --git a/test/testother.cpp b/test/testother.cpp index dc8b7d179..51d871c22 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -260,7 +260,7 @@ private: " if(a!=b)\n" " cout << a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) There are opposite condition checks in your nested-if block, which leads to a dead code block\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str()); check("void foo(int i) \n" "{\n" @@ -294,7 +294,7 @@ private: check("void foo(bool *p) {\n" " p = false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Assigning bool value to pointer (converting bool value to address)\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout.str()); } @@ -307,7 +307,7 @@ private: "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Division by zero.\n", errout.str()); } void zeroDiv2() { @@ -335,7 +335,7 @@ private: "{\n" " div_t divresult = div (1,0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); } void zeroDiv4() { @@ -349,25 +349,25 @@ private: "{\n" " long a = b / 0x0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); check("void f()\n" "{\n" " long a = b / 0L;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); check("void f()\n" "{\n" " long a = b / 0ul;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); check("void f()\n" "{\n" " div_t divresult = div (1,0L);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); check("void f()\n" "{\n" @@ -408,7 +408,7 @@ private: "{ { {\n" " long a = b / 0;\n" "} } }\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); } void zeroDiv6() { @@ -416,7 +416,7 @@ private: "{ { {\n" " int a = b % 0;\n" "} } }\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); } @@ -444,7 +444,7 @@ private: " char buf[100];\n" " sprintf(buf,\"%s\",buf);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Undefined behavior: variable is used as parameter and destination in s[n]printf().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in s[n]printf().\n", errout.str()); } void sprintf2() { @@ -507,7 +507,7 @@ private: "{\n" " const char *p = \"/usr\" + '/';\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Unusual pointer arithmetic\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal.\n", errout.str()); } void strPlusChar2() { @@ -628,7 +628,7 @@ private: " for ( ; i < 10; ++i) ;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced.\n", errout.str()); varScope("void f(int x) {\n" " const unsigned char i = 0;\n" @@ -636,7 +636,7 @@ private: " for ( ; i < 10; ++i) ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout.str()); varScope("void f(int x)\n" "{\n" @@ -646,7 +646,7 @@ private: " for ( ; i < 10; ++i) ;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced.\n", errout.str()); } void varScope6() { @@ -709,7 +709,7 @@ private: " edgeResistance = (edge+1) / 2.0;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'edgeResistance' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'edgeResistance' can be reduced.\n", errout.str()); } void varScope9() { @@ -769,7 +769,7 @@ private: " foo(i);\n" " foo(j);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout.str()); varScope("void f(int x) {\n" " int i[5];\n" @@ -786,7 +786,7 @@ private: " if (x == 5)\n" " foo(b);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'b' can be reduced\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'b' can be reduced.\n", errout.str()); varScope("void f(int x) {\n" " const bool b = x;\n" @@ -919,36 +919,36 @@ private: " delete [] (double*)f;\n" " delete [] (long double const*)(new float[10]);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation\n" - "[test.cpp:4]: (warning) Casting between float* and long double* which have an incompatible binary data representation\n", - "[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation\n" - "[test.cpp:4]: (warning) Casting between float* and double* which have an incompatible binary data representation\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (warning) Casting between float* and long double* which have an incompatible binary data representation.\n", + "[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(const float* f) {\n" " double *d = (double*)f;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between float* and double* which have an incompatible binary data representation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(double* d1) {\n" " long double *ld = (long double*)d1;\n" " double *d2 = (double*)ld;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and long double* which have an incompatible binary data representation\n" - "[test.cpp:3]: (warning) Casting between long double* and double* which have an incompatible binary data representation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and long double* which have an incompatible binary data representation.\n" + "[test.cpp:3]: (warning) Casting between long double* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("char* test(int* i) {\n" " long double *d = (long double*)(i);\n" " double *d = (double*)(i);\n" " float *f = reinterpret_cast(i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and long double* which have an incompatible binary data representation\n" - "[test.cpp:3]: (warning) Casting between integer* and double* which have an incompatible binary data representation\n" - "[test.cpp:4]: (warning) Casting between integer* and float* which have an incompatible binary data representation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and long double* which have an incompatible binary data representation.\n" + "[test.cpp:3]: (warning) Casting between integer* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and float* which have an incompatible binary data representation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i[0];\n" @@ -958,7 +958,7 @@ private: checkInvalidPointerCast("float* test(double& d) {\n" " return (float*)&d;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and float* which have an incompatible binary data representation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" @@ -968,7 +968,7 @@ private: checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" "}", true, true); // #3639 - ASSERT_EQUALS("[test.cpp:2]: (portability, inconclusive) Casting from float* to char* might be not portable due to different binary data representations on different platforms\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability, inconclusive) Casting from float* to char* is not portable due to different binary data representations on different platforms.\n", errout.str()); checkInvalidPointerCast("long long* test(float* f) {\n" @@ -980,7 +980,7 @@ private: " foo((long long*)f);\n" " return reinterpret_cast(c);\n" "}", true); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting from float* to integer* is not portable due to different binary data representations on different platforms\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting from float* to integer* is not portable due to different binary data representations on different platforms.\n", errout.str()); checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)"); // #4135 - don't crash } @@ -992,7 +992,7 @@ private: " return strtol(num, NULL, 1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid radix in call to strtol or strtoul. Must be 0 or 2-36\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Invalid radix in call to strtol(). It must be 0 or 2-36.\n", errout.str()); } { @@ -1068,43 +1068,43 @@ private: "{\n" " std::cout << log(-2) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -2 to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -2 to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(-1.) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1. to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1. to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(-1.0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.0 to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.0 to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(-0.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -0.1 to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -0.1 to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(0.) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0. to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0. to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << log(0.0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0.0 to log() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0.0 to log() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" @@ -1162,19 +1162,19 @@ private: "{\n" " std::cout << acos(1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 1.1 to acos() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 1.1 to acos() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << acos(-1.1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.1 to acos() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.1 to acos() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" " std::cout << acos(-110) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -110 to acos() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -110 to acos() leads to undefined result.\n", errout.str()); // atan2 @@ -1198,7 +1198,7 @@ private: "{\n" " std::cout << atan2(0,0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and 0 to atan2() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing values 0 and 0 to atan2() leads to undefined result.\n", errout.str()); // fmod @@ -1206,7 +1206,7 @@ private: "{\n" " std::cout << fmod(1.0,0) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 1.0 and 0 to fmod() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing values 1.0 and 0 to fmod() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" @@ -1220,7 +1220,7 @@ private: "{\n" " std::cout << pow(0,-10) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and -10 to pow() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing values 0 and -10 to pow() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" @@ -1233,7 +1233,7 @@ private: "{\n" " std::cout << sqrt(-1) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1 to sqrt() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1 to sqrt() leads to undefined result.\n", errout.str()); check("void foo()\n" "{\n" @@ -1256,7 +1256,7 @@ private: "{\n" " std::cout << isalnum(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalnum() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalnum() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1268,7 +1268,7 @@ private: "{\n" " std::cout << isalpha(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalpha() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalpha() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1280,7 +1280,7 @@ private: "{\n" " std::cout << iscntrl(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to iscntrl() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to iscntrl() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1292,7 +1292,7 @@ private: "{\n" " std::cout << isdigit(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isdigit() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isdigit() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1304,7 +1304,7 @@ private: "{\n" " std::cout << isgraph(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isgraph() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isgraph() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1316,7 +1316,7 @@ private: "{\n" " std::cout << islower(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to islower() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to islower() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1328,7 +1328,7 @@ private: "{\n" " std::cout << isprint(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isprint() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isprint() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1340,7 +1340,7 @@ private: "{\n" " std::cout << ispunct(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to ispunct() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to ispunct() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1352,7 +1352,7 @@ private: "{\n" " std::cout << isspace(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isspace() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isspace() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1364,7 +1364,7 @@ private: "{\n" " std::cout << isupper(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isupper() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isupper() causes undefined behavior which may lead to a crash.\n", errout.str()); check("void foo()\n" "{\n" @@ -1376,12 +1376,12 @@ private: "{\n" " std::cout << isxdigit(-61) << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isxdigit() cause undefined behavior, which may lead to a crash\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isxdigit() causes undefined behavior which may lead to a crash.\n", errout.str()); + check("void f() {\n" "std::isgraph(-10000, loc);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Passing value -10000 to isgraph() cause undefined behavior, which may lead to a crash\n", errout.str()); - + ASSERT_EQUALS("[test.cpp:2]: (error) Passing value -10000 to isgraph() causes undefined behavior which may lead to a crash.\n", errout.str()); } void sizeofsizeof() { @@ -1389,30 +1389,30 @@ private: "{\n" " int i = sizeof sizeof char;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Calling 'sizeof' on 'sizeof'.\n", errout.str()); check("void foo()\n" "{\n" " int i = sizeof (sizeof long);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Calling 'sizeof' on 'sizeof'.\n", errout.str()); check("void foo(long *p)\n" "{\n" " int i = sizeof (sizeof (p));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Calling 'sizeof' on 'sizeof'.\n", errout.str()); } void sizeofCalculation() { check("int a, b; int a,sizeof(a+b)"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(a*b)"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(-a)"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); check("int a, b; sizeof(*a)"); ASSERT_EQUALS("", errout.str()); @@ -1435,7 +1435,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1451,7 +1451,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1612,7 +1612,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" "{\n" @@ -1624,7 +1624,7 @@ private: " strcpy(str, \"b'\");\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" "{\n" @@ -1636,7 +1636,7 @@ private: " strncpy(str, \"b'\");\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" "{\n" @@ -1651,7 +1651,7 @@ private: " z++;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Buffer 'str' is being written before its old content has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" "{\n" @@ -1694,7 +1694,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1709,7 +1709,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1748,7 +1748,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1763,7 +1763,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1802,7 +1802,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1817,7 +1817,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1856,7 +1856,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -1871,7 +1871,7 @@ private: " }\n" " bar(y);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. This might indicate a missing 'break;'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -2034,7 +2034,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on \"y\" in switch\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" "{\n" @@ -2048,7 +2048,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on \"y\" in switch\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" "{\n" @@ -2122,7 +2122,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on \"y\" in switch\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" "{\n" @@ -2250,7 +2250,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2261,7 +2261,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2324,7 +2324,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2353,7 +2353,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2366,7 +2366,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2380,7 +2380,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2394,7 +2394,7 @@ private: " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2425,7 +2425,7 @@ private: // that all paths after g() actually return. It's a pretty unusual case // (no pun intended). TODO_ASSERT_EQUALS("", - "[test.cpp:11]: (style) Switch falls through case without comment\n", errout.str()); + "[test.cpp:11]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2459,7 +2459,7 @@ private: // into where the goto is, but because it contains a "return", it omits // copying a final return after the block. TODO_ASSERT_EQUALS("", - "[test.cpp:5]: (style) Switch falls through case without comment\n", errout.str()); + "[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( "void foo() {\n" @@ -2709,19 +2709,19 @@ private: " x = x;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Redundant assignment of \"x\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); check("void foo()\n" "{\n" " int x = x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"x\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); check("void foo()\n" "{\n" " std::string var = var = \"test\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'var' to itself.\n", errout.str()); // #4073 (segmentation fault) check("void Foo::myFunc( int a )\n" @@ -2749,7 +2749,7 @@ private: " BAR *x = getx();\n" " x = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"x\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); // #2502 - non-primitive type -> there might be some side effects check("void foo()\n" @@ -2781,7 +2781,7 @@ private: "void f() {\n" " i = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"i\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'i' to itself.\n", errout.str()); } void trac1132() { @@ -2804,7 +2804,7 @@ private: " return 0;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:15]: (error) Instance of \"Lock\" object destroyed immediately.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:15]: (error) Instance of 'Lock' object is destroyed immediately.\n", errout.str()); } void trac3693() { @@ -2852,7 +2852,7 @@ private: " return 0 ;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:4]: (error) Instance of \"NotAFunction\" object destroyed immediately.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Instance of 'NotAFunction' object is destroyed immediately.\n", errout.str()); } void testMisusedScopeObjectPicksStruct() { @@ -2863,7 +2863,7 @@ private: " return true ;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:4]: (error) Instance of \"NotAClass\" object destroyed immediately.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Instance of 'NotAClass' object is destroyed immediately.\n", errout.str()); } void testMisusedScopeObjectDoesNotPickIf() { @@ -2917,7 +2917,7 @@ private: " Foo();\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:7]: (error) Instance of \"Foo\" object destroyed immediately.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Instance of 'Foo' object is destroyed immediately.\n", errout.str()); } void testMisusedScopeObjectDoesNotPickUsedObject() { @@ -2945,7 +2945,7 @@ private: "}\n"; check(code, "test.cpp"); - ASSERT_EQUALS("[test.cpp:7]: (error) Instance of \"cb_watch_bool\" object destroyed immediately.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Instance of 'cb_watch_bool' object is destroyed immediately.\n", errout.str()); check(code, "test.c"); ASSERT_EQUALS("", errout.str()); @@ -3572,7 +3572,7 @@ private: "}\n" ); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n" - "[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); // The second message appears because the code is simplified to "true == 6". Its neither wrong nor necessary. + "[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); // The second message appears because the code is simplified to "true == 6". Its neither wrong nor necessary. check("void f(int x) {\n" " if ((x || 0x0f)==0)\n" @@ -3687,56 +3687,56 @@ private: " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false < x )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x < false )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false > x )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x >= false )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false >= x )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x <= false )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false <= x )\n" " a++;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("typedef int (*func)(bool invert);\n" "void x(int, func f);\n" @@ -3816,15 +3816,13 @@ private: " memset(p, 10, 0x0);\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0" - " bytes of \'p\'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes of 'p'.\n", errout.str()); check("void f() {\n" " memset(p, sizeof(p), 0);\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0" - " bytes of \'p\'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes of 'p'.\n", errout.str()); check("void f() {\n" " memset(p, sizeof(p), i+0);\n" @@ -3887,22 +3885,22 @@ private: " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as " - "function argument returns the size of pointer.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Using 'sizeof' on array given as " + "function argument returns size of a pointer.\n", errout.str()); check("void f( int a[]) {\n" " std::cout << sizeof a / sizeof(int) << std::endl;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as " - "function argument returns the size of pointer.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Using 'sizeof' on array given as " + "function argument returns size of a pointer.\n", errout.str()); check("void f( int a[3] ) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as " - "function argument returns the size of pointer.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Using 'sizeof' on array given as " + "function argument returns size of a pointer.\n", errout.str()); check("void f(int *p) {\n" " p[0] = 0;\n" @@ -3945,16 +3943,16 @@ private: " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as " - "function argument returns the size of pointer.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Using 'sizeof' on array given as " + "function argument returns size of a pointer.\n", errout.str()); // ticket #2510 check("void f( int a[3] , int b[2] ) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as " - "function argument returns the size of pointer.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Using 'sizeof' on array given as " + "function argument returns size of a pointer.\n", errout.str()); // ticket #2510 check("void f() {\n" @@ -3971,28 +3969,28 @@ private: "}\n", NULL, true ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof(-10) << std::endl;\n" "}\n", NULL, true ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof 10 << std::endl;\n" "}\n", NULL, true ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof -10 << std::endl;\n" "}\n", NULL, true ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); } @@ -4001,12 +3999,12 @@ private: check("int f(char c) {\n" " return 10 * (c == 0) ? 1 : 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for * and ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '*' and '?'.\n", errout.str()); check("void f(char c) {\n" " printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for * and ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '*' and '?'.\n", errout.str()); // Ticket #2585 - segmentation fault for invalid code check("abcdef?" "?<" @@ -4017,23 +4015,23 @@ private: check("void f(char c) {\n" " printf(\"%i\", 1 + 1 ? 1 : 2);\n" // "1+1" is simplified away "}"); - TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for + and ?\n", "", errout.str()); // TODO: Is that really necessary, or is this pattern too unlikely? + TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '+' and '?'.\n", "", errout.str()); // TODO: Is that really necessary, or is this pattern too unlikely? check("void f() {\n" " std::cout << x << 1 ? 2 : 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for << and ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '<<' and '?'.\n", errout.str()); check("void f() {\n" " int ab = a - b ? 2 : 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for - and ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '-' and '?'.\n", errout.str()); // ticket #195 check("int f(int x, int y) {\n" " return x >> ! y ? 8 : 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for >> and ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '>>' and '?'.\n", errout.str()); check("int f() {\n" " return (shift < sizeof(int64_t)*8 ? 1 : 2);\n" @@ -4109,7 +4107,7 @@ private: check("void f() {\n" " if (x = b() < 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (assignment+comparison), it can be clarified with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses.\n", errout.str()); check("void f(int i) {\n" " for (i = 0; i < 10; i++) {}\n" @@ -4128,12 +4126,12 @@ private: check("void f() {\n" " if (x & 2 == 2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n", errout.str()); check("void f() {\n" " if (a & fred1.x == fred2.y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n", errout.str()); } // clarify condition that uses ! operator and then bitwise operator @@ -4141,12 +4139,12 @@ private: check("void f(int w) {\n" " if(!w & 0x8000) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout.str()); check("void f() {\n" " if (x == foo() & 2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout.str()); check("void f(std::list &ints) { }"); ASSERT_EQUALS("", errout.str()); @@ -4155,7 +4153,7 @@ private: ASSERT_EQUALS("", errout.str()); check("void f() { a(x there are never templates - ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses\n", errout.str()); + ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout.str()); check("class A;", "test.C"); ASSERT_EQUALS("", errout.str()); @@ -4199,56 +4197,56 @@ private: check("void f(_Bool a, _Bool b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("void f(_Bool a, _Bool b) {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a & !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a | !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str()); check("bool a, b;\n" "void f() {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("bool a, b;\n" "void f() {\n" " if(a & !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("bool a, b;\n" "void f() {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str()); check("bool a, b;\n" "void f() {\n" " if(a | !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str()); check("void f(bool a, int b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("void f(int a, bool b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'b' is used in bitwise operation. Did you mean && ?\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean variable 'b' is used in bitwise operation. Did you mean '&&'?\n", errout.str()); check("void f(int a, int b) {\n" " if(a & b) {}\n" @@ -4265,7 +4263,7 @@ private: check("int f() {\n" " return test.substr( 0 , 4 ) == \"Hello\" ? : 0 : 1 ;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) String literal \"Hello\" doesn't match length argument for substr(4).\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) String literal \"Hello\" doesn't match length argument for substr().\n", errout.str()); check("int f() {\n" " return test.substr( 0 , 5 ) == \"Hello\" ? : 0 : 1 ;\n" @@ -4275,7 +4273,7 @@ private: check("int f() {\n" " return \"Hello\" == test.substr( 0 , 4 ) ? : 0 : 1 ;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) String literal \"Hello\" doesn't match length argument for substr(4).\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) String literal \"Hello\" doesn't match length argument for substr().\n", errout.str()); check("int f() {\n" " return \"Hello\" == test.substr( 0 , 5 ) ? : 0 : 1 ;\n" @@ -4285,27 +4283,27 @@ private: check("int f() {\n" " if (\"Hello\") { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " if (\"Hello\" && 1) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " if (1 && \"Hello\") { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " while (\"Hello\") { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " assert (test || \"Hello\");\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " assert (test && \"Hello\");\n" @@ -4315,7 +4313,7 @@ private: check("int f() {\n" " assert (\"Hello\" || test);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) A boolean comparison with the string literal \"Hello\" is always true.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str()); check("int f() {\n" " assert (\"Hello\" && test);\n" @@ -4332,16 +4330,16 @@ private: void incrementBoolean() { check("bool bValue = true;\n" "bValue++;\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); check("_Bool bValue = true;\n" "bValue++;\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); check("void f(bool test){\n" " test++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); check("void f(int test){\n" " test++;\n" @@ -4355,14 +4353,14 @@ private: " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(bool x) {\n" " if (10 >= x) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(bool x) {\n" " if (x != 0) {\n" @@ -4382,14 +4380,14 @@ private: " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer that is neither 1 nor 0\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer that is neither 1 nor 0.\n", errout.str()); check("void f(bool x) {\n" " if (x == 10) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer that is neither 1 nor 0\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer that is neither 1 nor 0.\n", errout.str()); check("void f(bool x) {\n" " if (x == 0) {\n" @@ -4408,14 +4406,14 @@ private: " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(int x, bool y) {\n" " if (x == y) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(bool x, bool y) {\n" " if (x == y) {\n" @@ -4438,14 +4436,14 @@ private: " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(int y) {\n" " if (true == y) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); check("void f(bool y) {\n" " if (y == true) {\n" @@ -4459,7 +4457,7 @@ private: " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); } void comparisonOfBoolWithInt4() { @@ -4482,21 +4480,21 @@ private: " if (a) { b = 1; }\n" " else if (a) { b = 2; }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Found duplicate if expressions.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else if (a == 2) { b = 2; }\n" " else if (a == 1) { b = 3; }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate if expressions.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else if (a == 2) { b = 2; }\n" " else if (a == 2) { b = 3; }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) Found duplicate if expressions.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a == 1) {\n" @@ -4506,8 +4504,8 @@ private: " } else if (a == 2) { b = 2; }\n" " else if (a == 2) { b = 3; }\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (style) Found duplicate if expressions.\n" - "[test.cpp:5] -> [test.cpp:4]: (style) Found duplicate if expressions.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (style) Duplicate conditions in 'if' and related 'else if'.\n" + "[test.cpp:5] -> [test.cpp:4]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a++) { b = 1; }\n" @@ -4549,7 +4547,7 @@ private: " std::cout << \"A\";\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:7]: (style) Found duplicate if expressions.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:7]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); } void duplicateBranch() { @@ -4559,7 +4557,7 @@ private: " else\n" " b = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a) {\n" @@ -4570,7 +4568,7 @@ private: " } else\n" " b = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f(int a, int &b) {\n" " if (a == 1)\n" @@ -4580,7 +4578,7 @@ private: " else\n" " b = 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("int f(int signed, unsigned char value) {\n" " int ret;\n" @@ -4606,7 +4604,7 @@ private: " else\n" " __asm__(\"mov ax, bx\");\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); } void duplicateBranch1() { @@ -4620,7 +4618,7 @@ private: " else \n" " frac = (front)/(front-back);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f()\n" "{\n" @@ -4629,7 +4627,7 @@ private: " else \n" " frac = (front)/(front-back);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f()\n" "{\n" @@ -4638,7 +4636,7 @@ private: " else \n" " frac = (front)/((front-back));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); } void duplicateExpression1() { @@ -4770,9 +4768,9 @@ private: " if (flt != flt) have_nan = 1;\n" " return have_nan;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Passing value -1.0 to sqrtl() leads to undefined result\n" - "[test.cpp:8]: (error) Passing value -1.0 to sqrt() leads to undefined result\n" - "[test.cpp:9]: (error) Passing value -1.0 to sqrtf() leads to undefined result\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Passing value -1.0 to sqrtl() leads to undefined result.\n" + "[test.cpp:8]: (error) Passing value -1.0 to sqrt() leads to undefined result.\n" + "[test.cpp:9]: (error) Passing value -1.0 to sqrtf() leads to undefined result.\n", errout.str()); } void duplicateExpression3() { @@ -4991,22 +4989,22 @@ private: check( "int *x = malloc(sizeof(x));\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(&x));\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(100 * sizeof(x));\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(x) * 100);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof *x);\n" @@ -5016,12 +5014,12 @@ private: check( "int *x = malloc(sizeof x);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(100 * sizeof x);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = calloc(1, sizeof(*x));\n" @@ -5036,12 +5034,12 @@ private: check( "int *x = calloc(1, sizeof(x));\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = calloc(1, sizeof x);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = calloc(1, sizeof(int));\n" @@ -5085,25 +5083,25 @@ private: "int *x = malloc(sizeof(int));\n" "memset(x, 0, sizeof x);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(int));\n" "memset(x, 0, sizeof(x));\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(int) * 10);\n" "memset(x, 0, sizeof(x) * 10);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(int) * 10);\n" "memset(x, 0, sizeof x * 10);\n" "free(x);"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Using size of pointer x instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str()); check( "int *x = malloc(sizeof(int) * 10);\n" @@ -5129,13 +5127,13 @@ private: " const char *buf1_ex = \"foobarbaz\";\n" " return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Using size of pointer buf1_ex instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Size of pointer 'buf1_ex' used instead of size of its data.\n", errout.str()); check( "int fun(const char *buf1) {\n" " return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Using size of pointer buf1 instead of size of its data.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'buf1' used instead of size of its data.\n", errout.str()); // #ticket 3874 check("void f()\n" @@ -5170,14 +5168,14 @@ private: " for(unsigned char i = 10; i >= 0; i--)" " printf(\"%u\", i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'i' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'i' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "void foo(bool b) {\n" " for(unsigned int i = 10; b || i >= 0; i--)" " printf(\"%u\", i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'i' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'i' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "bool foo(unsigned int x) {\n" @@ -5217,7 +5215,7 @@ private: " return true;\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "bool foo(int x) {\n" @@ -5266,7 +5264,7 @@ private: " return true;\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "bool foo(int x, bool y) {\n" @@ -5315,7 +5313,7 @@ private: " return true;\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "bool foo(int x, bool y) {\n" @@ -5364,7 +5362,7 @@ private: " return true;\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) An unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned variable 'x' can't be negative so it is unnecessary to test it.\n", errout.str()); check_signOfUnsignedVariable( "bool foo(int x, bool y) {\n" @@ -6011,7 +6009,7 @@ private: " const A a = getA();\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for a to avoid unnecessary data copying.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for 'a' to avoid unnecessary data copying.\n", errout.str()); check_redundant_copy("const int& getA(){static int a;return a;}\n" "int main()\n" @@ -6037,7 +6035,7 @@ private: " const A a(getA());\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for a to avoid unnecessary data copying.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for 'a' to avoid unnecessary data copying.\n", errout.str()); check_redundant_copy("const int& getA(){static int a;return a;}\n" "int main()\n"