From 53c714f8803e70991b83a42f7c2f88df4db2999c Mon Sep 17 00:00:00 2001 From: heliocodacy <46491761+heliocodacy@users.noreply.github.com> Date: Tue, 20 Jan 2026 11:50:21 +0000 Subject: [PATCH] Implement null pointer error demonstration Added functions to demonstrate null pointer dereferencing errors. --- cpp/include/ktbind/dummy.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cpp/include/ktbind/dummy.cpp diff --git a/cpp/include/ktbind/dummy.cpp b/cpp/include/ktbind/dummy.cpp new file mode 100644 index 0000000..7957bac --- /dev/null +++ b/cpp/include/ktbind/dummy.cpp @@ -0,0 +1,30 @@ +#include + +void causeNullPointerError() { + int* ptr = nullptr; // 1. Pointer is explicitly set to NULL + + // ... some other logic ... + + // 2. ERROR: Dereferencing the null pointer + *ptr = 42; + + std::cout << "Value: " << *ptr << std::endl; +} + +void checkAfterDereference(int* x) { + // 3. ERROR: Dereferencing 'x' before checking if it is null + *x = 10; + + if (x == nullptr) { + return; + } +} + +int main() { + causeNullPointerError(); + + int* val = nullptr; + checkAfterDereference(val); + + return 0; +}