From d81776b8c8f1bc9c1b8b47120bed9c07f9348db8 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Fri, 7 Aug 2015 17:16:41 +0300 Subject: [PATCH] Avoid deep copying std::string --- lib/checkio.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index c51038a65..53be34d6c 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -526,7 +526,6 @@ void CheckIO::checkWrongPrintfScanfArguments() const Token* argListTok = 0; // Points to first va_list argument const Token* formatStringTok = 0; // Points to format string token - std::string formatString; bool scan = false; bool scanf_s = false; @@ -589,18 +588,18 @@ void CheckIO::checkWrongPrintfScanfArguments() continue; } - if (formatStringTok) - formatString = formatStringTok->str(); - else + if (!formatStringTok) continue; + const std::string& formatString = formatStringTok->str(); + // Count format string parameters.. unsigned int numFormat = 0; unsigned int numSecure = 0; bool percent = false; const Token* argListTok2 = argListTok; std::set parameterPositionsUsed; - for (std::string::iterator i = formatString.begin(); i != formatString.end(); ++i) { + for (std::string::const_iterator i = formatString.begin(); i != formatString.end(); ++i) { if (*i == '%') { percent = !percent; } else if (percent && *i == '[') {