From f378b382a0326e8498aaf6b8fd3c3da4563d621b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 21 Apr 2010 20:06:59 +0200 Subject: [PATCH] CheckBufferOverrun: simplify checking of read|write problems --- lib/checkbufferoverrun.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 90f33853e..e681958dc 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -477,6 +477,12 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c total_size["strncpy"] = 3; total_size["memset"] = 3; } + + if (par == 2) + { + total_size["read"] = 3; + total_size["write"] = 3; + } std::map::const_iterator it = total_size.find(tok.str()); if (it != total_size.end()) @@ -1015,19 +1021,6 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo if (n > total_size) outOfBounds(tok->tokAt(4), "snprintf size"); } - - - // Writing data into array.. - if (Token::Match(tok, "read|write ( %any% , %varid% , %num% )", arrayInfo.varid) && - MathLib::isInt(tok->strAt(6))) - { - const unsigned long len = MathLib::toLongNumber(tok->strAt(6)); - if (len > total_size) - { - bufferOverrun(tok, arrayInfo.varname); - continue; - } - } } }