diff --git a/lib/checkio.cpp b/lib/checkio.cpp index e01ac44c8..136bb278a 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -524,7 +524,8 @@ void CheckIO::checkWrongPrintfScanfArguments() bool _continue = false; std::string width; - unsigned int parameterPosition = 0; bool hasParameterPosition = false; + unsigned int parameterPosition = 0; + bool hasParameterPosition = false; while (i != formatString.end() && *i != ']' && !std::isalpha(*i)) { if (*i == '*') { if (scan) @@ -550,10 +551,10 @@ void CheckIO::checkWrongPrintfScanfArguments() if (scan || *i != 'm') { // %m is a non-standard extension that requires no parameter on print functions. ++numFormat; - + // Handle parameter positions (POSIX extension) - Ticket #4900 - if(hasParameterPosition) { - if(parameterPositionsUsed.find(parameterPosition) == parameterPositionsUsed.end()) + if (hasParameterPosition) { + if (parameterPositionsUsed.find(parameterPosition) == parameterPositionsUsed.end()) parameterPositionsUsed.insert(parameterPosition); else // Parameter already referenced, hence don't consider it a new format --numFormat; @@ -733,10 +734,10 @@ void CheckIO::checkWrongPrintfScanfArguments() numFunction++; argListTok2 = argListTok2->nextArgument(); // Find next argument } - + // Check that all parameter positions reference an actual parameter - for(std::set::const_iterator it = parameterPositionsUsed.begin() ; it != parameterPositionsUsed.end() ; ++it) { - if((*it == 0) || (*it > numFormat)) + for (std::set::const_iterator it = parameterPositionsUsed.begin() ; it != parameterPositionsUsed.end() ; ++it) { + if ((*it == 0) || (*it > numFormat)) wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), *it, numFormat); } @@ -769,13 +770,13 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok, } void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName, - unsigned int index, unsigned int numFunction) + unsigned int index, unsigned int numFunction) { - if (!_settings->isEnabled("style")) + if (!_settings->isEnabled("warning")) return; std::ostringstream errmsg; errmsg << functionName << ": "; - if(index == 0) { + if (index == 0) { errmsg << "parameter positions start at 1, not 0"; } else { errmsg << "referencing parameter " << index << " while " << numFunction << " arguments given"; diff --git a/lib/checkio.h b/lib/checkio.h index 35477e864..9fba82865 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -83,7 +83,7 @@ private: unsigned int numFormat, unsigned int numFunction); void wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName, - unsigned int index, unsigned int numFunction); + unsigned int index, unsigned int numFunction); void invalidScanfArgTypeError(const Token* tok, const std::string &functionName, unsigned int numFormat); void invalidPrintfArgTypeError_s(const Token* tok, unsigned int numFormat); void invalidPrintfArgTypeError_n(const Token* tok, unsigned int numFormat); diff --git a/test/testio.cpp b/test/testio.cpp index e8448bec9..26fe520bd 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -786,7 +786,7 @@ private: " int bar;" " printf(\"%1$d\", 1);" " printf(\"%1$d, %d, %1$d\", 1, 2);" - " scanf(\"%1$d\", &bar);" + " scanf(\"%1$d\", &bar);" "}"); ASSERT_EQUALS("", errout.str());