From ea7f4a70c49a745ff79c6a14a6f1b2317ea4e747 Mon Sep 17 00:00:00 2001 From: Ken Domino Date: Sat, 5 Nov 2022 07:43:00 -0400 Subject: [PATCH 1/2] Fix for https://github.com/antlr/grammars-v4/issues/2909 https://github.com/antlr/antlr4/issues/3845 -- you cannot dereference a null pointer. --- runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp index 7dcc011d1d..cf840652f1 100755 --- a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +++ b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp @@ -22,6 +22,12 @@ namespace { } bool predictionContextEqual(const Ref &lhs, const Ref &rhs) { + if (lhs == nullptr && rhs == nullptr) + return true; + if (lhs == nullptr && !(rhs == nullptr)) + return false; + if (!(lhs == nullptr) && rhs == nullptr) + return false; return *lhs == *rhs; } From f736631e503cf0521fdf4d7c8737709422bae078 Mon Sep 17 00:00:00 2001 From: Ken Domino Date: Sun, 6 Nov 2022 18:44:29 -0500 Subject: [PATCH 2/2] Simplify. --- runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp index cf840652f1..b76e0d2726 100755 --- a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +++ b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp @@ -22,12 +22,10 @@ namespace { } bool predictionContextEqual(const Ref &lhs, const Ref &rhs) { - if (lhs == nullptr && rhs == nullptr) - return true; - if (lhs == nullptr && !(rhs == nullptr)) - return false; - if (!(lhs == nullptr) && rhs == nullptr) - return false; + if (lhs == nullptr) + return rhs == nullptr; + else if (rhs == nullptr) + return false; return *lhs == *rhs; }