From 120c57225256ea7a62d80c85afed512d28a22609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Jun 2020 15:24:01 +0200 Subject: [PATCH] Fixed #9750 (Chained stream operation gives uninitvar error) --- lib/astutils.cpp | 2 +- test/testuninitvar.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 031a6f124..d7926d83b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1353,7 +1353,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, } } - if (isLikelyStreamRead(cpp, tok->previous())) + if (cpp && Token::simpleMatch(tok2->astParent(), ">>") && tok2->astParent()->astOperand2() == tok2 && isLikelyStreamRead(cpp, tok2->astParent())) return true; if (isLikelyStream(cpp, tok2)) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 704b32a09..6cda95d44 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4242,14 +4242,26 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); - valueFlowUninit("struct S { int x; };\n" // #9417 - "void f() {\n" - " S s;\n" - " return s(1);\n" + // #9750 + valueFlowUninit("struct S {\n" + " int one;\n" + " int two;\n" + "};\n" + "\n" + "void test(std::istringstream& in) {\n" + " S p;\n" + " in >> p.one >> p.two;\n" "}"); ASSERT_EQUALS("", errout.str()); } + valueFlowUninit("struct S { int x; };\n" // #9417 + "void f() {\n" + " S s;\n" + " return s(1);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + valueFlowUninit("void a() {\n" // asm " int x;\n" " asm();\n"