From c487ea843dcacd2f28849805795cb52b599086df Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 9 Apr 2013 08:30:53 -0700 Subject: [PATCH] Better fix for #4706: Use Token::nextArgument() properly. Removed redundant ' in message --- lib/checkbufferoverrun.cpp | 12 ++++++------ test/testbufferoverrun.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 487dd735e..83f8a49b5 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -2248,14 +2248,14 @@ void CheckBufferOverrun::writeOutsideBufferSize() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { - if (Token::Match(tok, "pwrite|write (") && Token::Match(tok->tokAt(2), "%any% , %str% , %num%")) { + if (Token::Match(tok, "pwrite|write (") && Token::Match(tok->tokAt(2)->nextArgument(), "%str% , %num%")) { const std::string & functionName(tok->str()); - tok = tok->tokAt(4); // set tokenptr to %str% parameter + tok = tok->tokAt(2)->nextArgument(); // set tokenptr to %str% parameter const std::size_t stringLength = Token::getStrLength(tok); tok = tok->tokAt(2); // set tokenptr to %num% parameter const MathLib::bigint writeLength = MathLib::toLongNumber(tok->str()); - if (static_cast(writeLength) > stringLength) - writeOutsideBufferSizeError(tok, stringLength, writeLength,functionName); + if (static_cast(writeLength) > stringLength) + writeOutsideBufferSizeError(tok, stringLength, writeLength, functionName); } } } @@ -2264,8 +2264,8 @@ void CheckBufferOverrun::writeOutsideBufferSize() void CheckBufferOverrun::writeOutsideBufferSizeError(const Token *tok, const std::size_t stringLength, const MathLib::bigint writeLength, const std::string &strFunctionName) { reportError(tok, Severity::error, "writeOutsideBufferSize", - "Writing '" +MathLib::longToString(writeLength-stringLength)+"' bytes outside buffer size.\n" - "The number of bytes to write ('" +MathLib::longToString(writeLength)+ "' bytes) are bigger than the source buffer ('" +MathLib::longToString(stringLength)+ "' bytes)." + "Writing " + MathLib::longToString(writeLength-stringLength) + " bytes outside buffer size.\n" + "The number of bytes to write (" + MathLib::longToString(writeLength) + " bytes) are bigger than the source buffer (" +MathLib::longToString(stringLength)+ " bytes)." " Please check the second and the third parameter of the function '"+strFunctionName+"'."); } // ------------------------------------------------------------------------------------- diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index af157227d..fc784abf7 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4098,7 +4098,7 @@ private: check("void f(void){\n" "write(1, \"Dump string \\n\", 100);\n" "}"); // ^ number of bytes too big - ASSERT_EQUALS("[test.cpp:2]: (error) Writing '87' bytes outside buffer size.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Writing 87 bytes outside buffer size.\n", errout.str()); check("void f(void){\n" "write(1, \"Dump string \\n\", 10);\n" @@ -4113,7 +4113,7 @@ private: "{\n" " write(p.i[1], \"\", 1);\n" "}"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Writing 1 bytes outside buffer size.\n", errout.str()); } };