Skip to content

Commit 15d3e51

Browse files
committed
ValueFlow: throw TerminateException in valueFlowGenericForward in case analysis is terminated
1 parent 4e75c08 commit 15d3e51

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/cppcheck.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ unsigned int CppCheck::check(const std::string &path)
534534
} catch (const InternalError &e) {
535535
internalError(path, e.errorMessage);
536536
mExitCode = 1; // e.g. reflect a syntax error
537+
} catch (const TerminateException &) {
538+
// Analysis is terminated
539+
return mExitCode;
537540
} catch (const std::exception &e) {
538541
internalError(path, e.what());
539542
}
@@ -911,6 +914,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
911914
--checkCount; // don't count invalid configurations
912915
continue;
913916

917+
} catch (const TerminateException &) {
918+
// Analysis is terminated
919+
return mExitCode;
920+
914921
} catch (const InternalError &e) {
915922
std::list<ErrorMessage::FileLocation> locationList;
916923
if (e.token) {
@@ -962,6 +969,9 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
962969

963970
executeAddons(dumpFile);
964971

972+
} catch (const TerminateException &) {
973+
// Analysis is terminated
974+
return mExitCode;
965975
} catch (const std::runtime_error &e) {
966976
internalError(filename, e.what());
967977
} catch (const std::bad_alloc &e) {

lib/errortypes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "config.h"
2525

26+
#include <stdexcept>
2627
#include <list>
2728
#include <string>
2829
#include <utility>
@@ -41,6 +42,11 @@ struct InternalError {
4142
std::string id;
4243
};
4344

45+
class TerminateException: public std::runtime_error {
46+
public:
47+
TerminateException(): std::runtime_error("terminate") {}
48+
};
49+
4450
class CPPCHECKLIB Certainty {
4551
public:
4652
enum CertaintyLevel {

lib/forwardanalyzer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const V
889889

890890
Analyzer::Result valueFlowGenericForward(Token* start, const ValuePtr<Analyzer>& a, const Settings* settings)
891891
{
892+
if (Settings::terminated())
893+
throw TerminateException();
892894
ForwardTraversal ft{a, settings};
893895
ft.updateRecursive(start);
894896
return Analyzer::Result{ ft.actions, ft.terminate };

0 commit comments

Comments
 (0)