From 1a8d0fd1529452ddca34492ea5f7c2f34d090103 Mon Sep 17 00:00:00 2001 From: Miika-Petteri Matikainen Date: Tue, 11 Oct 2016 19:46:46 +0300 Subject: [PATCH] Fixes preprocessor regression causing hang Cppcheck 1.76 introduced a regression in preprocessor which causes the following code to hang: $ cat > test.c << EOF #ifndef Y #else #endif EOF $ cppcheck -D BAR --force test.c Checking test.c ... ^C This used to work with version 1.75. Git bisect reveals that this regression was caused by commit: ff036c8742e8f3a0a54d36dbbbb9845af7d22c53 This commit fixes the regression by avoiding infinite loop in hasDefine(). If cfg is empty string "", we can skip the whole loop and exit early. --- lib/preprocessor.cpp | 4 ++++ test/testpreprocessor.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 9d0f47a25..a74813a36 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -217,6 +217,10 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set