Permalink
Browse files

Better fix for #4706: Use Token::nextArgument() properly. Removed red…

…undant ' in message
  • Loading branch information...
1 parent 4c8b17c commit c487ea843dcacd2f28849805795cb52b599086df @PKEuS PKEuS committed Apr 9, 2013
Showing with 8 additions and 8 deletions.
  1. +6 −6 lib/checkbufferoverrun.cpp
  2. +2 −2 test/testbufferoverrun.cpp
View
@@ -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<unsigned long int>(writeLength) > stringLength)
- writeOutsideBufferSizeError(tok, stringLength, writeLength,functionName);
+ if (static_cast<std::size_t>(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+"'.");
}
// -------------------------------------------------------------------------------------
@@ -4098,7 +4098,7 @@ class TestBufferOverrun : public TestFixture {
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 @@ class TestBufferOverrun : public TestFixture {
"{\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());
}
};

0 comments on commit c487ea8

Please sign in to comment.