From aa457b54dfe8767c693c5e52e035788c22064db0 Mon Sep 17 00:00:00 2001 From: Sunny Chatterjee Date: Mon, 25 Oct 2021 18:17:08 -0600 Subject: [PATCH 1/2] Adding CppCon example --- CMakeLists.txt | 3 ++- CppConDemo/CMakeLists.txt | 12 ++++++++++++ CppConDemo/CppConDemo.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 CppConDemo/CMakeLists.txt create mode 100644 CppConDemo/CppConDemo.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fd609c..aa77d0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,5 @@ cmake_minimum_required (VERSION 3.20.5) project(CppAnalysisExamples) add_subdirectory(CodeQL) -add_subdirectory(CppCoreCheck) \ No newline at end of file +add_subdirectory(CppCoreCheck) +add_subdirectory(CppConDemo) \ No newline at end of file diff --git a/CppConDemo/CMakeLists.txt b/CppConDemo/CMakeLists.txt new file mode 100644 index 0000000..73d4d03 --- /dev/null +++ b/CppConDemo/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.20.5) + +add_library (CppCon + CppConDemo.cpp +) + +set_target_properties(CppCon + PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF +) \ No newline at end of file diff --git a/CppConDemo/CppConDemo.cpp b/CppConDemo/CppConDemo.cpp new file mode 100644 index 0000000..5f65901 --- /dev/null +++ b/CppConDemo/CppConDemo.cpp @@ -0,0 +1,27 @@ +enum class AUTH_STATE { Nothing }; + +struct AUTH_CONTEXT +{ + AUTH_STATE authState; +}; + +struct Connection +{ + AUTH_CONTEXT* context_; +}; + +void CleanupContext(Connection* pConnection); + +void InitializeContext(Connection* pConnection) +{ + AUTH_CONTEXT* pContext = nullptr; + if (!pConnection) + { + CleanupContext(pConnection); + } + else + { + pContext = pConnection->context_; + } + pContext->authState = AUTH_STATE::Nothing; +} From c7f7fd23f4e38203e6dd0c0001f124916e5c538f Mon Sep 17 00:00:00 2001 From: Sunny Chatterjee Date: Mon, 25 Oct 2021 18:23:19 -0600 Subject: [PATCH 2/2] Enable null dereference checking in ruleset --- All.ruleset | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/All.ruleset b/All.ruleset index 4490319..5bba13e 100644 --- a/All.ruleset +++ b/All.ruleset @@ -1,5 +1,5 @@  - + @@ -88,5 +88,6 @@ + \ No newline at end of file