From 946722faf05d8d9308df16f03edb42996fa47d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 5 Oct 2013 18:25:44 +0200 Subject: [PATCH] Fixed #4968 (False positive: Structure with 'read' member is confused with read() function.) --- lib/checkbufferoverrun.cpp | 19 ++++++++++++------- test/testbufferoverrun.cpp | 9 +++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 896ab7ffe..bca5b523f 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -577,15 +577,20 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p } else if (par == 2) { - total_size["read"] = 3; - total_size["pread"] = 3; - total_size["write"] = 3; - total_size["recv"] = 3; - total_size["recvfrom"] = 3; - total_size["send"] = 3; - total_size["sendto"] = 3; + if (_settings->standards.posix) { + total_size["read"] = 3; + total_size["pread"] = 3; + total_size["write"] = 3; + total_size["recv"] = 3; + total_size["recvfrom"] = 3; + total_size["send"] = 3; + total_size["sendto"] = 3; + } } + if (Token::Match(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::")) + total_size.clear(); + std::map::const_iterator it = total_size.find(tok.str()); if (it != total_size.end()) { if (arrayInfo.element_size() == 0) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index aafce26f5..ea4658062 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2162,6 +2162,15 @@ private: "sendto(s, str, 4, 0, 0x0, 0x0);\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: str\n", errout.str()); + + // #4968 - not standard function + check("void f() {\n" + " char str[3];\n" + " foo.memset(str, 0, 100);\n" + " foo::memset(str, 0, 100);\n" + " std::memset(str, 0, 100);\n" + "}"); + ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", errout.str()); }