Skip to content

Commit 4a06a25

Browse files
committed
moved reading of UNUSEDFUNCTION_ONLY into a single place
1 parent 971bf0f commit 4a06a25

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
347347

348348
SuppressionList supprlist;
349349

350-
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
351-
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
350+
const bool doUnusedFunctionOnly = Settings::doUnusedFunctionOnly();
352351
// ignore all other suppressions if we use the unusedFunction hack
353352
for (auto&& s : suppr)
354353
{

lib/cppcheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation
13401340

13411341
// TODO: this should actually be the behavior if only "--enable=unusedFunction" is specified - see #10648
13421342
// TODO: log message when this is active?
1343-
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
1344-
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
1343+
const bool doUnusedFunctionOnly = Settings::doUnusedFunctionOnly();
13451344

13461345
if (!doUnusedFunctionOnly) {
13471346
const std::time_t maxTime = mSettings.checksMaxTime > 0 ? std::time(nullptr) + mSettings.checksMaxTime : 0;

lib/settings.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,9 @@ Settings::ExecutorType Settings::defaultExecutor()
715715
#endif
716716
return defaultExecutor;
717717
}
718+
719+
bool Settings::doUnusedFunctionOnly()
720+
{
721+
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
722+
return unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
723+
}

lib/settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,10 @@ class CPPCHECKLIB WARN_UNUSED Settings {
554554

555555
void setCheckLevel(CheckLevel level);
556556

557-
558557
static ExecutorType defaultExecutor();
559558

559+
static bool doUnusedFunctionOnly();
560+
560561
private:
561562
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity>, SimpleEnableGroup<Checks>> &groups);
562563
std::string applyEnabled(const std::string &str, bool enable);

0 commit comments

Comments
 (0)