From 5164d87a2e5099c6435f97049dd80bdd9aaa4e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 28 Jun 2020 22:49:51 +0200 Subject: [PATCH] Bug hunting; Fixed false positives for containers --- lib/bughuntingchecks.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/bughuntingchecks.cpp b/lib/bughuntingchecks.cpp index c97a3172d..c674d50c4 100644 --- a/lib/bughuntingchecks.cpp +++ b/lib/bughuntingchecks.cpp @@ -185,6 +185,29 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine: return; } + // container is not uninitialized + if (tok->valueType() && tok->valueType()->pointer==0 && tok->valueType()->container) + return; + + // container element is not uninitialized + if (tok->str() == "[" && + tok->astOperand1() && + tok->astOperand1()->valueType() && + tok->astOperand1()->valueType()->pointer==0 && + tok->astOperand1()->valueType()->container) { + if (tok->astOperand1()->valueType()->container->stdStringLike) + return; + bool pointerType = false; + for (const Token *typeTok = tok->astOperand1()->valueType()->containerTypeToken; Token::Match(typeTok, "%name%|*|::|<"); typeTok = typeTok->next()) { + if (typeTok->str() == "<" && typeTok->link()) + typeTok = typeTok->link(); + if (typeTok->str() == "*") + pointerType = true; + } + if (!pointerType) + return; + } + // lhs in assignment if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1()) return;