From 3d0f335b74873fd94bfb919e96b666fcc70c2dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Feb 2025 12:47:01 +0100 Subject: [PATCH 1/7] releasenotes: tweaks [skip ci] --- releasenotes.txt | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/releasenotes.txt b/releasenotes.txt index ab79c15db37..dee7ac7ffb7 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -3,24 +3,17 @@ Release Notes for Cppcheck 2.17 New checks: - staticFunction: detect functions that should have internal linkage since they are not used outside of their translation unit (C code only). -- Check null pointer return from memory/resource allocation functions (nullPointerOutOfMemory, nullPointerArithmeticOutOfMemory, nullPointerOutOfResources, ctunullpointerOutOfMemory, ctunullpointerOutOfResources). - -Improved checking: -- - -GUI: -- +- Check null pointer return from memory/resource allocation functions (nullPointerOutOfMemory, + nullPointerArithmeticOutOfMemory, nullPointerOutOfResources, ctunullpointerOutOfMemory, + ctunullpointerOutOfResources). Changed interface: --Added `reduced` check level. It can be activated with `--check-level=reduced`. You get faster analysis -but some fewer results. The motivation is to be able to make analysis time "acceptable" for direct usage. - --Added `--report-type` option. Enables printing of guidelines and classifications for several coding -standards in place of the regular error identifiers and severities. - -Deprecations: -- +- Added `reduced` check level. It can be activated with `--check-level=reduced`. You get faster analysis + but some fewer results. The motivation is to be able to make analysis time "acceptable" for direct usage. +- Added `--report-type` option. Enables printing of guidelines and classifications for several coding + standards in place of the regular error identifiers and severities. Other: - Removed deperecated support for builds via qmake. -- +- Using a handwritten rule texts file for MISRA C addon violates license and copyright terms. See the + manual for instructions how to download a official rule texts file from MISRA. From 70e6e33ce179e9002ac621d71851e30569e4d865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Feb 2025 12:52:53 +0100 Subject: [PATCH 2/7] 2.17: Set version --- CMakeLists.txt | 2 +- cli/main.cpp | 2 +- lib/version.h | 4 ++-- man/manual.md | 2 +- man/reference-cfg-format.md | 2 +- man/writing-addons.md | 2 +- win_installer/productInfo.wxi | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d70dd10ffc4..53c9b1578f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(Cppcheck VERSION 2.16.99 LANGUAGES CXX) +project(Cppcheck VERSION 2.17.0 LANGUAGES CXX) include(cmake/options.cmake) diff --git a/cli/main.cpp b/cli/main.cpp index 4e6f61efae8..5a38b6eb22e 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -20,7 +20,7 @@ /** * * @mainpage Cppcheck - * @version 2.16.99 + * @version 2.17.0 * * @section overview_sec Overview * Cppcheck is a simple tool for static analysis of C/C++ code. diff --git a/lib/version.h b/lib/version.h index 6370e90741f..8af26f8cac1 100644 --- a/lib/version.h +++ b/lib/version.h @@ -23,9 +23,9 @@ #define versionH #define CPPCHECK_MAJOR_VERSION 2 -#define CPPCHECK_MINOR_VERSION 16 +#define CPPCHECK_MINOR_VERSION 17 #define CPPCHECK_DEVMINOR_VERSION 17 -#define CPPCHECK_BUGFIX_VERSION 99 +#define CPPCHECK_BUGFIX_VERSION 0 #define STRINGIFY(x) STRING(x) #define STRING(VER) #VER diff --git a/man/manual.md b/man/manual.md index 695f9fba5de..5fd9e8ab1bf 100644 --- a/man/manual.md +++ b/man/manual.md @@ -1,6 +1,6 @@ --- title: Cppcheck manual -subtitle: Version 2.16.99 +subtitle: Version 2.17 author: Cppcheck team lang: en documentclass: report diff --git a/man/reference-cfg-format.md b/man/reference-cfg-format.md index fcf123049b0..327a1ce01b6 100644 --- a/man/reference-cfg-format.md +++ b/man/reference-cfg-format.md @@ -1,6 +1,6 @@ --- title: Cppcheck .cfg format -subtitle: Version 2.16.99 +subtitle: Version 2.17 author: Cppcheck team lang: en documentclass: report diff --git a/man/writing-addons.md b/man/writing-addons.md index 070be0a48a3..f57a4489ea4 100644 --- a/man/writing-addons.md +++ b/man/writing-addons.md @@ -1,6 +1,6 @@ --- title: Writing addons -subtitle: Version 2.16.99 +subtitle: Version 2.17 author: Cppcheck team lang: en documentclass: report diff --git a/win_installer/productInfo.wxi b/win_installer/productInfo.wxi index d5f519c2c98..bbbd822eb26 100644 --- a/win_installer/productInfo.wxi +++ b/win_installer/productInfo.wxi @@ -1,8 +1,8 @@ - + - + From 560b5340ea84bcdf53e3100f7d2ee434bdb305e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Feb 2025 12:54:23 +0100 Subject: [PATCH 3/7] 2.17.0: Updated Makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2bc08f1ead3..d94d793df37 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ ifeq (clang++, $(findstring clang++,$(CXX))) CPPCHK_GLIBCXX_DEBUG= endif ifndef CXXFLAGS - CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-sign-compare -Wno-multichar -Woverloaded-virtual $(CPPCHK_GLIBCXX_DEBUG) -g + CXXFLAGS=-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar endif ifeq (g++, $(findstring g++,$(CXX))) @@ -364,7 +364,7 @@ dmake: tools/dmake/dmake.o cli/filelister.o $(libcppdir)/pathmatch.o $(libcppdir $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) run-dmake: dmake - ./dmake + ./dmake --release clean: rm -f build/*.cpp build/*.o lib/*.o cli/*.o test/*.o tools/dmake/*.o externals/*/*.o testrunner dmake cppcheck cppcheck.exe cppcheck.1 From 2cec7ebcdc6808bddbd1230649e55add07656ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 24 Feb 2025 16:28:33 +0100 Subject: [PATCH 4/7] fixed #13656 - fixed stack-use-after-scope in GUI (#7331) --- gui/checkthread.cpp | 5 +++-- gui/checkthread.h | 5 +++-- gui/mainwindow.cpp | 17 +++++++++-------- gui/threadhandler.cpp | 2 +- gui/threadhandler.h | 3 ++- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index a36680c64bc..3d1a44a9a18 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -110,11 +111,11 @@ CheckThread::CheckThread(ThreadResult &result) : mResult(result) {} -void CheckThread::setSettings(const Settings &settings, Suppressions& supprs) +void CheckThread::setSettings(const Settings &settings, std::shared_ptr supprs) { mFiles.clear(); mSettings = settings; // this is a copy - mSuppressions = &supprs; + mSuppressions = std::move(supprs); } void CheckThread::analyseWholeProgram(const QStringList &files, const std::string& ctuInfo) diff --git a/gui/checkthread.h b/gui/checkthread.h index fc5fd393d5a..827e75f1247 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -55,7 +56,7 @@ class CheckThread : public QThread { * @param settings settings for cppcheck * @param supprs suppressions for cppcheck */ - void setSettings(const Settings &settings, Suppressions& supprs); + void setSettings(const Settings &settings, std::shared_ptr supprs); /** * @brief Run whole program analysis @@ -132,7 +133,7 @@ class CheckThread : public QThread { ThreadResult &mResult; Settings mSettings; - Suppressions* mSuppressions{}; + std::shared_ptr mSuppressions; private: void runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 618de4352d6..15ac3936288 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -542,8 +543,8 @@ void MainWindow::saveSettings() const void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration) { Settings checkSettings; - Suppressions supprs; - if (!getCppcheckSettings(checkSettings, supprs)) + auto supprs = std::make_shared(); + if (!getCppcheckSettings(checkSettings, *supprs)) return; clearResults(); @@ -613,8 +614,8 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar return; Settings checkSettings; - Suppressions supprs; - if (!getCppcheckSettings(checkSettings, supprs)) + auto supprs = std::make_shared(); + if (!getCppcheckSettings(checkSettings, *supprs)) return; clearResults(); @@ -1348,8 +1349,8 @@ void MainWindow::reAnalyzeSelected(const QStringList& files) } Settings checkSettings; - Suppressions supprs; - if (!getCppcheckSettings(checkSettings, supprs)) + auto supprs = std::make_shared(); + if (!getCppcheckSettings(checkSettings, *supprs)) return; // Clear details, statistics and progress @@ -1383,8 +1384,8 @@ void MainWindow::reAnalyze(bool all) return; Settings checkSettings; - Suppressions supprs; - if (!getCppcheckSettings(checkSettings, supprs)) + auto supprs = std::make_shared(); + if (!getCppcheckSettings(checkSettings, *supprs)) return; // Clear details, statistics and progress diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index f72bbdc53a5..fecfb44b23b 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -83,7 +83,7 @@ void ThreadHandler::setCheckFiles(const QStringList& files) } } -void ThreadHandler::check(const Settings &settings, Suppressions& supprs) +void ThreadHandler::check(const Settings &settings, const std::shared_ptr& supprs) { if (mResults.getFileCount() == 0 || mRunningThreadCount > 0 || settings.jobs == 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; diff --git a/gui/threadhandler.h b/gui/threadhandler.h index ec2c9b81260..49a326933b0 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -23,6 +23,7 @@ #include "suppressions.h" #include "threadresult.h" +#include #include #include @@ -117,7 +118,7 @@ class ThreadHandler : public QObject { * @param settings Settings for checking * @param supprs Suppressions for checking */ - void check(const Settings &settings, Suppressions& supprs); + void check(const Settings &settings, const std::shared_ptr& supprs); /** * @brief Set files to check From 521d5d844d48def80bb2b6fb96e9a34f459bb8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 24 Feb 2025 16:29:07 +0100 Subject: [PATCH 5/7] Fix #13633 (safety: the xml version 3 report should show safety properties) (#7298) --- cli/cppcheckexecutor.cpp | 9 +++++++++ test/cli/premium_test.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index c2877a44d8a..86b4831b94c 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -532,6 +532,15 @@ void StdLogger::writeCheckersReport(const Suppressions& supprs) if (xmlReport) { reportErr(" \n"); + if (mSettings.safety) + reportErr(" \n"); + if (mSettings.inlineSuppressions) + reportErr(" \n"); + if (!suppressions.empty()) { + std::ostringstream suppressionsXml; + supprs.nomsg.dump(suppressionsXml); + reportErr(suppressionsXml.str()); + } reportErr(checkersReport.getXmlReport(mCriticalErrors)); } } diff --git a/test/cli/premium_test.py b/test/cli/premium_test.py index d0d50389b2a..55adf772467 100644 --- a/test/cli/premium_test.py +++ b/test/cli/premium_test.py @@ -55,6 +55,22 @@ def test_misra_c_builtin_style_checks(tmpdir): assert 'id="unusedVariable"' in stderr assert 'id="checkersReport"' not in stderr + exitcode, _, stderr = cppcheck(['--xml-version=3', test_file], cppcheck_exe=exe) + assert exitcode == 0 + assert '' in stderr + + exitcode, _, stderr = cppcheck(['--xml-version=3', '--premium=safety-off', test_file], cppcheck_exe=exe) + assert exitcode == 0 + assert '' not in stderr + + exitcode, _, stderr = cppcheck(['--xml-version=3', '--inline-suppr', test_file], cppcheck_exe=exe) + assert exitcode == 0 + assert '' in stderr + + exitcode, _, stderr = cppcheck(['--xml-version=3', '--suppress=foo', test_file], cppcheck_exe=exe) + assert exitcode == 0 + assert '' in stderr + def test_build_dir_hash_cppcheck_product(tmpdir): # 13644 - cppcheck build dir hashes should depend on the cppcheck version @@ -97,3 +113,4 @@ def _get_hash(s:str): assert hash1 != hash2 + From ac9db3069b9f90e81e126a090b99ad456e122cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 26 Feb 2025 13:56:41 +0100 Subject: [PATCH 6/7] 2.17.1: Set version --- CMakeLists.txt | 2 +- cli/main.cpp | 2 +- lib/version.h | 6 +++--- win_installer/productInfo.wxi | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53c9b1578f8..e0d10caeb3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(Cppcheck VERSION 2.17.0 LANGUAGES CXX) +project(Cppcheck VERSION 2.17.1 LANGUAGES CXX) include(cmake/options.cmake) diff --git a/cli/main.cpp b/cli/main.cpp index 5a38b6eb22e..824aff8b209 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -20,7 +20,7 @@ /** * * @mainpage Cppcheck - * @version 2.17.0 + * @version 2.17.1 * * @section overview_sec Overview * Cppcheck is a simple tool for static analysis of C/C++ code. diff --git a/lib/version.h b/lib/version.h index 8af26f8cac1..32408dd7723 100644 --- a/lib/version.h +++ b/lib/version.h @@ -1,6 +1,6 @@ /* -*- C++ -*- * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2024 Cppcheck team. + * Copyright (C) 2007-2025 Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ #define CPPCHECK_MAJOR_VERSION 2 #define CPPCHECK_MINOR_VERSION 17 #define CPPCHECK_DEVMINOR_VERSION 17 -#define CPPCHECK_BUGFIX_VERSION 0 +#define CPPCHECK_BUGFIX_VERSION 1 #define STRINGIFY(x) STRING(x) #define STRING(VER) #VER @@ -36,6 +36,6 @@ #define CPPCHECK_VERSION_STRING STRINGIFY(CPPCHECK_MAJOR_VERSION) "." STRINGIFY(CPPCHECK_DEVMINOR_VERSION) " dev" #define CPPCHECK_VERSION CPPCHECK_MAJOR_VERSION,CPPCHECK_MINOR_VERSION,99,0 #endif -#define LEGALCOPYRIGHT L"Copyright (C) 2007-2024 Cppcheck team." +#define LEGALCOPYRIGHT L"Copyright (C) 2007-2025 Cppcheck team." #endif diff --git a/win_installer/productInfo.wxi b/win_installer/productInfo.wxi index bbbd822eb26..57fabc12bcd 100644 --- a/win_installer/productInfo.wxi +++ b/win_installer/productInfo.wxi @@ -1,8 +1,8 @@ - + - + From e35065700b03db1edf7e31d8909751172c1e5d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 2 Apr 2025 14:25:10 +0200 Subject: [PATCH 7/7] fixed building outdated (pre-3.5) CMake projects in CI (#7420) CMake 4.0 removed support for projects targeting versions prior to 3.5. --- .github/workflows/CI-windows.yml | 4 +++- .github/workflows/format.yml | 2 +- .github/workflows/release-windows.yml | 4 +++- .github/workflows/selfcheck.yml | 2 +- externals/pcre.patch | 12 ++++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 externals/pcre.patch diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 39ba6d6f626..a414bfc3f02 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -127,9 +127,11 @@ jobs: - name: Install PCRE if: steps.cache-pcre.outputs.cache-hit != 'true' run: | + @echo on 7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! cd pcre-%PCRE_VERSION% || exit /b !errorlevel! - cmake . -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPCRE_BUILD_PCRECPP=Off -DPCRE_BUILD_TESTS=Off -DPCRE_BUILD_PCREGREP=Off || exit /b !errorlevel! + git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel! + cmake . -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPCRE_BUILD_PCRECPP=Off -DPCRE_BUILD_TESTS=Off -DPCRE_BUILD_PCREGREP=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 || exit /b !errorlevel! nmake || exit /b !errorlevel! copy pcre.h ..\externals || exit /b !errorlevel! copy pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel! diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 77d8af0e9a1..05e9dbe25ac 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -38,7 +38,7 @@ jobs: run: | wget https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.tar.gz tar xzvf uncrustify-0.72.0.tar.gz && cd uncrustify-uncrustify-0.72.0 - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 cmake --build build -- -j$(nproc) -s mkdir ~/uncrustify cd build && cp uncrustify ~/uncrustify/ diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index dc5cca2955c..73477772179 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -54,9 +54,11 @@ jobs: - name: Install PCRE if: steps.cache-pcre.outputs.cache-hit != 'true' run: | + @echo on 7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! cd pcre-%PCRE_VERSION% || exit /b !errorlevel! - cmake . -G "Visual Studio 17 2022" -A x64 -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF || exit /b !errorlevel! + git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel! + cmake . -G "Visual Studio 17 2022" -A x64 -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5 || exit /b !errorlevel! msbuild -m PCRE.sln -p:Configuration=Release -p:Platform=x64 || exit /b !errorlevel! copy pcre.h ..\externals || exit /b !errorlevel! copy Release\pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel! diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml index 2d0046cf68a..024dfd9579d 100644 --- a/.github/workflows/selfcheck.yml +++ b/.github/workflows/selfcheck.yml @@ -160,7 +160,7 @@ jobs: - name: CMake (corpus / no test) run: | - cmake -S cppcheck-2.8 -B cmake.output.corpus -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On + cmake -S cppcheck-2.8 -B cmake.output.corpus -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCMAKE_POLICY_VERSION_MINIMUM=3.5 - name: Generate dependencies (corpus) run: | diff --git a/externals/pcre.patch b/externals/pcre.patch new file mode 100644 index 00000000000..bf23435c934 --- /dev/null +++ b/externals/pcre.patch @@ -0,0 +1,12 @@ +diff -urN pcre/CMakeLists.txt pcre-8.45/CMakeLists.txt +--- pcre/CMakeLists.txt 2021-11-05 13:28:16.000000000 +0100 ++++ pcre-8.45/CMakeLists.txt 2025-04-02 10:18:49.636009900 +0200 +@@ -77,7 +77,7 @@ + # CMP0026 to avoid warnings for the use of LOCATION in GET_TARGET_PROPERTY. + + CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5) +-CMAKE_POLICY(SET CMP0026 OLD) ++#CMAKE_POLICY(SET CMP0026 OLD) + + # For FindReadline.cmake. This was changed to allow setting CMAKE_MODULE_PATH + # on the command line.