From 2831bbd420383818e49a334dc347fbed29f30bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 1 Jan 2015 14:29:49 +0100 Subject: [PATCH] ValueFlow: better handling of goto to avoid false positives --- lib/valueflow.cpp | 4 ++-- test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 286b65566..037dc58e8 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -243,11 +243,11 @@ static bool isReturn(const Token *tok) // noreturn function if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %var% (")) return true; - // return statement + // return/goto statement prev = prev->previous(); while (prev && !Token::Match(prev,"[;{}]")) prev = prev->previous(); - return Token::Match(prev, "[;{}] return"); + return Token::Match(prev, "[;{}] return|goto"); } return false; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6a615da33..52ed15e6b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -737,6 +737,14 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 4U, 32)); + code = "void f() {\n" + " int x = 33;\n" + " if (x==33) goto fail;\n" + " a[x]=0;\n" + "fail:\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 4U, 33)); + code = "void f() {\n" " int x = 32;\n" " if (a==1) { z=x+12; }\n"