diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 672bc35..44b0054 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,32 +8,28 @@ on: env: build: '${{ github.workspace }}/build' + config: 'Debug' result: '${{ github.workspace }}/build/results.sarif' jobs: build: - name: Run Analysis + name: Analyze runs-on: windows-latest steps: - name: Checkout action uses: actions/checkout@v2.3.4 - - name: Initialize & Build - uses: lukka/run-cmake@v3 - with: - cmakeListsTxtPath: ${{ github.workspace }}/CMakeLists.txt - buildDirectory: ${{ env.build }} - cmakeGenerator: VS16Win64 + - name: Configure CMake + run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }} - name: Run Analysis - id: run-analysis - continue-on-error: true uses: microsoft/msvc-code-analysis-action@main + id: run-analysis with: cmakeBuildDirectory: ${{ env.build }} + buildConfiguration: ${{ env.config }} ruleset: All.ruleset - ignoreSystemHeaders: true - name: Upload SARIF to Github uses: github/codeql-action/upload-sarif@v1 diff --git a/All.ruleset b/All.ruleset index 4490319..26d82a9 100644 --- a/All.ruleset +++ b/All.ruleset @@ -1,6 +1,7 @@  + diff --git a/Cppcorecheck/CppCoreCheck.cpp b/Cppcorecheck/CppCoreCheck.cpp index 8fe6b04..41d722e 100644 --- a/Cppcorecheck/CppCoreCheck.cpp +++ b/Cppcorecheck/CppCoreCheck.cpp @@ -1,29 +1,44 @@ // ConsoleApp.cpp : This file contains the 'main' function. Program execution begins and ends there. // -#include +// Trigger new workflow... -// update... +#include +#include int main() { - int* p = 0; - int q = 1; - if (q) - { - return *(p + 1); - } return 0; } +std::optional getTempOptional() noexcept { return {}; } + +void RefrenceToTemp() noexcept +{ + if (const auto val = *getTempOptional()) // C26815 + { + (void)val; + } +} + void RawPointerAssignment() { // C26400: No Raw Pointer Assignment (r.11) // C26409: Avoid call new or delete explicitly (r.11) - //char* buffer = new char[30]; + char* buffer = new char[30]; - // BUG: FIX // C26481: Don't use pointer arithmetic. Use span instead (bounds.1) - //buffer[0] = 'a'; + buffer[0] = 'a'; +} + +int NullDereference() +{ + const int* p = 0; + const int q = 1; + if (q) + { + return *(p + 1); + } + return 0; } struct MyStruct {