From 15d3e510e1c928d33bf3c78707401153ddea02d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 12 Nov 2022 12:47:54 +0100 Subject: [PATCH] ValueFlow: throw TerminateException in valueFlowGenericForward in case analysis is terminated --- lib/cppcheck.cpp | 10 ++++++++++ lib/errortypes.h | 6 ++++++ lib/forwardanalyzer.cpp | 2 ++ 3 files changed, 18 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index ac41c66bd..57979464e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -534,6 +534,9 @@ unsigned int CppCheck::check(const std::string &path) } catch (const InternalError &e) { internalError(path, e.errorMessage); mExitCode = 1; // e.g. reflect a syntax error + } catch (const TerminateException &) { + // Analysis is terminated + return mExitCode; } catch (const std::exception &e) { internalError(path, e.what()); } @@ -911,6 +914,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string --checkCount; // don't count invalid configurations continue; + } catch (const TerminateException &) { + // Analysis is terminated + return mExitCode; + } catch (const InternalError &e) { std::list locationList; if (e.token) { @@ -962,6 +969,9 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string executeAddons(dumpFile); + } catch (const TerminateException &) { + // Analysis is terminated + return mExitCode; } catch (const std::runtime_error &e) { internalError(filename, e.what()); } catch (const std::bad_alloc &e) { diff --git a/lib/errortypes.h b/lib/errortypes.h index bcfd44b5b..f7a3a51ec 100644 --- a/lib/errortypes.h +++ b/lib/errortypes.h @@ -23,6 +23,7 @@ #include "config.h" +#include #include #include #include @@ -41,6 +42,11 @@ struct InternalError { std::string id; }; +class TerminateException: public std::runtime_error { +public: + TerminateException(): std::runtime_error("terminate") {} +}; + class CPPCHECKLIB Certainty { public: enum CertaintyLevel { diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index fa74ecab1..abae3dd70 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -889,6 +889,8 @@ Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const V Analyzer::Result valueFlowGenericForward(Token* start, const ValuePtr& a, const Settings* settings) { + if (Settings::terminated()) + throw TerminateException(); ForwardTraversal ft{a, settings}; ft.updateRecursive(start); return Analyzer::Result{ ft.actions, ft.terminate };