Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<size_t size>
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);
Expand All @@ -199,6 +199,16 @@ class TestNullPointer : public TestFixture {
runChecks<CheckNullPointer>(tokenizer, this);
}

template<size_t size>
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<CheckNullPointer>(tokenizer, this);
}

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
template<size_t size>
void checkP_(const char* file, int line, const char (&code)[size]) {
Expand Down Expand Up @@ -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));
Expand Down
Loading