ValueFlow: throw TerminateException in valueFlowGenericForward in case analysis is terminated

This commit is contained in:
Daniel Marjamäki 2022-11-12 12:47:54 +01:00
parent 4e75c08f58
commit 15d3e510e1
3 changed files with 18 additions and 0 deletions

View File

@ -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<ErrorMessage::FileLocation> 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) {

View File

@ -23,6 +23,7 @@
#include "config.h"
#include <stdexcept>
#include <list>
#include <string>
#include <utility>
@ -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 {

View File

@ -889,6 +889,8 @@ Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const V
Analyzer::Result valueFlowGenericForward(Token* start, const ValuePtr<Analyzer>& a, const Settings* settings)
{
if (Settings::terminated())
throw TerminateException();
ForwardTraversal ft{a, settings};
ft.updateRecursive(start);
return Analyzer::Result{ ft.actions, ft.terminate };