From 8c4260519c3221081beeddb715c930c6f27f4251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 10 Jan 2009 14:27:31 +0000 Subject: [PATCH] sprintf: fixed bug "false positive when variable is used again after snprintf" --- src/checkother.cpp | 2 +- test/testother.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/checkother.cpp b/src/checkother.cpp index 78c7a5317..7c36772a6 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -344,7 +344,7 @@ void CheckOther::InvalidFunctionUsage() tok2 = tok2->next(); // is any source buffer overlapping the target buffer? - unsigned int parlevel = 0; + int parlevel = 0; while ((tok2 = tok2->next()) != NULL) { if (tok2->str() == "(") diff --git a/test/testother.cpp b/test/testother.cpp index f6e34ed65..544f72515 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -39,6 +39,7 @@ private: TEST_CASE(sprintf1); // Dangerous usage of sprintf TEST_CASE(sprintf2); + TEST_CASE(sprintf3); } void check(const char code[]) @@ -125,6 +126,18 @@ private: "}\n"); ASSERT_EQUALS(std::string(""), errout.str()); } + + void sprintf3() + { + sprintfUsage("void foo()\n" + "{\n" + " char buf[100];\n" + " sprintf(buf,\"%i\",sizeof(buf));\n" + " if (buf[0]);\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + }; REGISTER_TEST(TestOther)