From f0f69ed818f09bea049b87485411172b817d0d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Jun 2012 12:41:00 +0200 Subject: [PATCH] Reviewed handling of << and >> in C files in CheckUninitVar --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d15209b9f..2cdc3e67f 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -558,7 +558,7 @@ private: return tok.tokAt(3); } - else if (Token::Match(tok.previous(), "<<|>>") || Token::simpleMatch(tok.next(), "=")) { + else if ((!isC && Token::Match(tok.previous(), "<<|>>")) || Token::simpleMatch(tok.next(), "=")) { // TODO: Don't bail out for "<<" and ">>" if these are // just computations ExecutionPath::bailOutVar(checks, tok.varId()); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d2ac22d7d..99618b285 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -348,14 +348,21 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); - checkUninitVar("int a()\n" - "{\n" + checkUninitVar("int a() {\n" " int ret;\n" " std::cin >> ret;\n" " return ret;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a() {\n" + " int ret;\n" + " int a = value >> ret;\n" + " return ret;\n" + "}\n", + "test.c"); + ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout.str()); + checkUninitVar("void foo() {\n" // #3707 " Node node;\n" " int x;\n" @@ -370,6 +377,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a() {\n" + " int ret;\n" + " int a = value << ret;\n" + " return ret;\n" + "}\n", + "test.c"); + ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout.str()); + checkUninitVar("int a()\n" "{\n" " int ret;\n"