From 1fe008ba4b68ff48d881056793059dde88136fbc Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 28 Jul 2013 20:33:49 +0200 Subject: [PATCH] Ensure wrongPrintfScanfParameterPositionError is shown by 'cppcheck --errorlist'. --- lib/checkio.cpp | 6 ++---- lib/checkio.h | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 136bb278a..be50a8351 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -737,7 +737,7 @@ void CheckIO::checkWrongPrintfScanfArguments() // 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)) + if (((*it == 0) || (*it > numFormat)) && _settings->isEnabled("warning")) wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), *it, numFormat); } @@ -772,8 +772,6 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok, void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName, unsigned int index, unsigned int numFunction) { - if (!_settings->isEnabled("warning")) - return; std::ostringstream errmsg; errmsg << functionName << ": "; if (index == 0) { @@ -781,7 +779,7 @@ void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, cons } else { errmsg << "referencing parameter " << index << " while " << numFunction << " arguments given"; } - reportError(tok, Severity::warning, "wrongPrintfScanfParameterError", errmsg.str()); + reportError(tok, Severity::warning, "wrongPrintfScanfParameterPositionError", errmsg.str()); } void CheckIO::invalidScanfArgTypeError(const Token* tok, const std::string &functionName, unsigned int numFormat) diff --git a/lib/checkio.h b/lib/checkio.h index 9fba82865..250e121a0 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -115,6 +115,7 @@ private: c.invalidPrintfArgTypeError_sint(0, 1, "i"); c.invalidPrintfArgTypeError_float(0, 1, "f"); c.invalidScanfFormatWidthError(0, 10, 5, NULL); + c.wrongPrintfScanfPosixParameterPositionError(0, "printf", 2, 1); } static std::string myName() {