From 4330a43acbc978e5d133bacb2fac306e410bb554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 11 Nov 2020 22:47:23 +0100 Subject: [PATCH] Fixed #9933 (FP: uninitvar when reading to struct) --- lib/astutils.cpp | 2 ++ test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 667717058..a8cf1b09f 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1368,6 +1368,8 @@ const Token * getTokenArgumentFunction(const Token * tok, int& argn) parent = parent->astParent(); while (parent && parent->isCast()) parent = parent->astParent(); + if (Token::Match(parent, "[+-]") && parent->valueType() && parent->valueType()->pointer) + parent = parent->astParent(); // passing variable to subfunction? if (Token::Match(parent, "[(,{]")) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 06aa3509f..9b0a9797e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4109,6 +4109,17 @@ private: "}"; values = tokenValues(code, "szHdr ; }"); ASSERT_EQUALS(0, values.size()); + + // #9933 + code = "struct MyStruct { size_t value; }\n" + "\n" + "void foo() {\n" + " MyStruct x;\n" + " fread(((char *)&x) + 0, sizeof(x), f);\n" + " if (x.value < 432) {}\n" + "}"; + values = tokenValues(code, "x . value"); + ASSERT_EQUALS(0, values.size()); } void valueFlowTerminatingCond() {