From 396bd73844e4e0e00851f360120a9974bb70aa98 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 29 Apr 2026 09:08:12 +0200 Subject: [PATCH] TestNullPointer: avoid unnecessary `Settings` creation --- test/testnullpointer.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 967cd0d2315..04d2f61fc0c 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -37,6 +37,7 @@ class TestNullPointer : public TestFixture { private: const Settings settings = settingsBuilder().library("std.cfg").severity(Severity::warning).build(); + const Settings settings_i = settingsBuilder(settings).certainty(Certainty::inconclusive).build(); void run() override { mNewTemplate = true; @@ -183,13 +184,12 @@ class TestNullPointer : public TestFixture { { bool inconclusive = false; bool cpp = true; - Standards::cstd_t cstd = Standards::CLatest; }; #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) template void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) { - const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).c(options.cstd).build(); + const Settings& settings1 = options.inconclusive ? settings_i : settings; // Tokenize.. SimpleTokenizer tokenizer(settings1, *this, options.cpp); @@ -199,6 +199,16 @@ class TestNullPointer : public TestFixture { runChecks(tokenizer, this); } + template + void check_(const char* file, int line, const char (&code)[size], bool cpp, const Settings& s) { + // Tokenize.. + SimpleTokenizer tokenizer(s, *this, cpp); + ASSERT_LOC(tokenizer.tokenize(code), file, line); + + // Check for null pointer dereferences.. + runChecks(tokenizer, this); + } + #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) template void checkP_(const char* file, int line, const char (&code)[size]) { @@ -1338,7 +1348,8 @@ class TestNullPointer : public TestFixture { check(code); // C++ file => nullptr means NULL ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: i [nullPointer]\n", errout_str()); - check(code, dinit(CheckOptions, $.cpp = false, $.cstd = Standards::C17)); // C17 file => nullptr does not mean NULL + const Settings s = settingsBuilder(settings).c(Standards::C17).build(); + check(code, false, s); // C17 file => nullptr does not mean NULL ASSERT_EQUALS("", errout_str()); check(code, dinit(CheckOptions, $.cpp = false));