From e5eabc4e4730f7ed7fd0f2735baf3e64cc998f10 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 12 Jul 2022 15:23:33 +0200 Subject: [PATCH] C++: Slightly tweak nullness test and update test results --- .../controlflow/nullness/nullness.expected | 11 ++++++++--- .../library-tests/controlflow/nullness/nullness.ql | 1 - .../test/library-tests/controlflow/nullness/test.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cpp/ql/test/library-tests/controlflow/nullness/nullness.expected b/cpp/ql/test/library-tests/controlflow/nullness/nullness.expected index db5c795fd5b..bcf301ba47b 100644 --- a/cpp/ql/test/library-tests/controlflow/nullness/nullness.expected +++ b/cpp/ql/test/library-tests/controlflow/nullness/nullness.expected @@ -7,9 +7,14 @@ | test.cpp:15:8:15:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is not null | is valid | | test.cpp:16:8:16:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is null | is not valid | | test.cpp:17:9:17:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid | -| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid | +| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid | | test.cpp:19:9:19:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid | -| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid | +| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid | | test.cpp:21:9:21:14 | ... = ... | test.cpp:5:13:5:13 | v | is null | is not valid | | test.cpp:21:9:21:14 | ... = ... | test.cpp:7:10:7:10 | b | is not null | is valid | -| test.cpp:22:17:22:17 | b | test.cpp:7:10:7:10 | b | is not null | is valid | +| test.cpp:22:9:22:14 | ... = ... | test.cpp:5:13:5:13 | v | is not null | is not valid | +| test.cpp:22:9:22:14 | ... = ... | test.cpp:7:13:7:13 | c | is not null | is not valid | +| test.cpp:22:17:22:17 | c | test.cpp:7:13:7:13 | c | is not null | is valid | +| test.cpp:23:21:23:21 | x | test.cpp:23:14:23:14 | x | is not null | is valid | +| test.cpp:24:9:24:18 | (condition decl) | test.cpp:5:13:5:13 | v | is not null | is not valid | +| test.cpp:24:9:24:18 | (condition decl) | test.cpp:24:14:24:14 | y | is not null | is valid | diff --git a/cpp/ql/test/library-tests/controlflow/nullness/nullness.ql b/cpp/ql/test/library-tests/controlflow/nullness/nullness.ql index ed1ba15aa2b..864fd04f920 100644 --- a/cpp/ql/test/library-tests/controlflow/nullness/nullness.ql +++ b/cpp/ql/test/library-tests/controlflow/nullness/nullness.ql @@ -2,7 +2,6 @@ import cpp from AnalysedExpr a, LocalScopeVariable v, string isNullCheck, string isValidCheck where - a.getParent() instanceof IfStmt and v.getAnAccess().getEnclosingStmt() = a.getParent() and (if a.isNullCheck(v) then isNullCheck = "is null" else isNullCheck = "is not null") and (if a.isValidCheck(v) then isValidCheck = "is valid" else isValidCheck = "is not valid") diff --git a/cpp/ql/test/library-tests/controlflow/nullness/test.cpp b/cpp/ql/test/library-tests/controlflow/nullness/test.cpp index 03369c811d5..407753be17a 100644 --- a/cpp/ql/test/library-tests/controlflow/nullness/test.cpp +++ b/cpp/ql/test/library-tests/controlflow/nullness/test.cpp @@ -4,7 +4,7 @@ long __builtin_expect(long); void f(int *v) { int *w; - bool b; + bool b, c; if (v) {} if (!v) {} @@ -19,5 +19,7 @@ void f(int *v) { if (true && !v) {} if (!v && true) {} if (b = !v) {} - if (b = !v; b) {} + if (c = !v; c) {} + if (int *x = v; x) {} + if (int *y = v) {} }