From a9480ca0c18c76908d89c6b70ff3c68c0fe839da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 13 Mar 2012 21:19:10 +0100 Subject: [PATCH] CheckBufferOverrun: move condition before loop --- lib/checkbufferoverrun.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index bd666f6ae..8eac976fb 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1136,14 +1136,13 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo // strncpy takes entire variable length as input size unsigned int num = (unsigned int)MathLib::toLongNumber(tok->strAt(6 + offset)); - if (num >= total_size) { + // this is currently 'inconclusive'. See TestBufferOverrun::terminateStrncpy3 + if (num >= total_size && _settings->isEnabled("style") && _settings->inconclusive) { const Token *tok2 = tok->next()->link()->next(); for (; tok2; tok2 = tok2->next()) { if (tok2->varId() == tok->tokAt(2)->varId()) { if (!Token::Match(tok2, "%varid% [ %any% ] = 0 ;", tok->tokAt(2)->varId())) { - // this is currently 'inconclusive'. See TestBufferOverrun::terminateStrncpy3 - if (_settings->isEnabled("style") && _settings->inconclusive) - terminateStrncpyError(tok, tok->strAt(2)); + terminateStrncpyError(tok, tok->strAt(2)); } break;