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/CMakeLists.txt b/CMakeLists.txt index d70dd10ffc4..e0d10caeb3c 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.1 LANGUAGES CXX) include(cmake/options.cmake) 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 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/cli/main.cpp b/cli/main.cpp index 4e6f61efae8..824aff8b209 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -20,7 +20,7 @@ /** * * @mainpage Cppcheck - * @version 2.16.99 + * @version 2.17.1 * * @section overview_sec Overview * Cppcheck is a simple tool for static analysis of C/C++ code. 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. 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 diff --git a/lib/version.h b/lib/version.h index 6370e90741f..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 @@ -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 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/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/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. 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 + diff --git a/win_installer/productInfo.wxi b/win_installer/productInfo.wxi index d5f519c2c98..57fabc12bcd 100644 --- a/win_installer/productInfo.wxi +++ b/win_installer/productInfo.wxi @@ -1,8 +1,8 @@ - + - +