From d95f3bce11c5e174471dc0fc150b49fd8a033b69 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:01:00 +0200 Subject: [PATCH 1/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index d5a2b4f019b..8be16f3a19f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5635,6 +5635,28 @@ class TestValueFlow : public TestFixture { value = valueOfTok(code, ", 1"); ASSERT_EQUALS(0, value.intvalue); ASSERT_EQUALS(false, value.isKnown()); + + // #13959 + const Settings settingsOld = settings; + settings = settingsBuilder(settingsOld).c(Standards::C23).build(); + code = "void f(int* p) {\n" // #11894 + " if (p == nullptr)\n" + " return;\n" + " if (p) {}\n" + "}\n"; + value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false); + ASSERT_EQUALS(1, value.intvalue); + ASSERT_EQUALS(true, value.isKnown()); + + settings = settingsBuilder(settingsOld).c(Standards::C17).build(); + code = "void f(int* p) {\n" // #11894 + " if (p == nullptr)\n" + " return;\n" + " if (p) {}\n" + "}\n"; + value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false); + ASSERT(value == ValueFlow::Value()); + settings = settingsOld; } void valueFlowSizeofForwardDeclaredEnum() { From fc118aa6bdf8dd1dd1454878de8fcf82554ea46d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:02:24 +0200 Subject: [PATCH 2/5] Update vf_common.cpp --- lib/vf_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vf_common.cpp b/lib/vf_common.cpp index eeb19c2381c..0498a7e303d 100644 --- a/lib/vf_common.cpp +++ b/lib/vf_common.cpp @@ -150,7 +150,7 @@ namespace ValueFlow if (!tok->isTemplateArg()) value.setKnown(); setTokenValue(tok, std::move(value), settings); - } else if (tok->str() == "NULL" || (tok->isCpp() && tok->str() == "nullptr")) { + } else if (tok->str() == "NULL" || ((tok->isCpp() || settings.standards.c >= Standards::C23) && tok->str() == "nullptr")) { Value value(0); if (!tok->isTemplateArg()) value.setKnown(); From 9ea083070a3200cb28cc14bd2e54f1ca20ce79a2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:04:09 +0200 Subject: [PATCH 3/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8be16f3a19f..86fa02b9191 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5639,7 +5639,7 @@ class TestValueFlow : public TestFixture { // #13959 const Settings settingsOld = settings; settings = settingsBuilder(settingsOld).c(Standards::C23).build(); - code = "void f(int* p) {\n" // #11894 + code = "void f(int* p) {\n" " if (p == nullptr)\n" " return;\n" " if (p) {}\n" @@ -5649,11 +5649,6 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(true, value.isKnown()); settings = settingsBuilder(settingsOld).c(Standards::C17).build(); - code = "void f(int* p) {\n" // #11894 - " if (p == nullptr)\n" - " return;\n" - " if (p) {}\n" - "}\n"; value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false); ASSERT(value == ValueFlow::Value()); settings = settingsOld; From f15835a9325fb899e27f4dcaa7d8d5988d7c53ec Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:26:16 +0200 Subject: [PATCH 4/5] Update testnullpointer.cpp --- test/testnullpointer.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 1e21479d5ab..dfdfc472a1a 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -183,12 +183,13 @@ class TestNullPointer : public TestFixture { CheckOptions() = default; 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).build(); + const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).c(options.cstd).build(); // Tokenize.. SimpleTokenizer tokenizer(settings1, *this, options.cpp); @@ -201,7 +202,7 @@ class TestNullPointer : public TestFixture { #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) template void checkP_(const char* file, int line, const char (&code)[size]) { - const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).build(); + const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).c(options.cstd).build(); SimpleTokenizer2 tokenizer(settings1, *this, code, "test.cpp"); @@ -1331,8 +1332,11 @@ 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)); // C file => nullptr does not mean NULL + check(code, dinit(CheckOptions, $.cpp = false, $.cstd = Standards::C17)); // C17 file => nullptr does not mean NULL ASSERT_EQUALS("", errout_str()); + + check(code, dinit(CheckOptions, $.cpp = false)); + ASSERT_EQUALS("[test.c:4:11]: (error) Null pointer dereference: i [nullPointer]\n", errout_str()); } void nullpointer15() { // #3560 From bc7ac8319cc3b7a144051c0122deb2d7aa3ced3b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Jun 2025 10:55:27 +0200 Subject: [PATCH 5/5] Update testnullpointer.cpp --- test/testnullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index dfdfc472a1a..1028c527275 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -202,7 +202,7 @@ class TestNullPointer : public TestFixture { #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) template void checkP_(const char* file, int line, const char (&code)[size]) { - const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).c(options.cstd).build(); + const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).build(); SimpleTokenizer2 tokenizer(settings1, *this, code, "test.cpp");