From e1fd7c59d002a44c2307e7135476547c13daca36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 7 Nov 2026 21:15:34 +0100 Subject: [PATCH 1/3] Fix #10610 (Support for PCRE2) Replace the discontinued PCRE library with PCRE2 for rules PCRE (8.x) is end of life and is being removed from Linux distributions. - lib/regex.cpp: use the PCRE2 API (with JIT when available) - fix endless loop when a rule pattern matches an empty string - CMake, Makefile, dmake and Visual Studio project use PCRE2 - CI installs/builds PCRE2 instead of PCRE - update documentation Rule files and the "pcre" engine name are unchanged. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI-unixish-docker.yml | 8 +- .github/workflows/CI-unixish.yml | 12 +- .github/workflows/CI-windows.yml | 40 +++-- .github/workflows/clang-tidy.yml | 2 +- .github/workflows/iwyu.yml | 10 +- .github/workflows/release-windows.yml | 24 +-- .github/workflows/sanitizers.yml | 2 +- .gitignore | 6 +- Makefile | 8 +- build-pcre.txt | 55 +++--- cli/cmdlineparser.cpp | 2 +- cmake/findDependencies.cmake | 6 +- cmake/options.cmake | 2 +- externals/pcre.patch | 12 -- lib/cppcheck.vcxproj | 4 +- lib/regex.cpp | 215 +++++------------------- man/writing-rules-1.docbook | 6 +- readme.md | 11 +- readmeja.md | 13 +- releasenotes.txt | 2 + requirements.txt | 2 +- test/testregex.cpp | 18 ++ tools/dmake/dmake.cpp | 8 +- 23 files changed, 160 insertions(+), 308 deletions(-) delete mode 100644 externals/pcre.patch diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index 02afca633b7..94174689caa 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -51,7 +51,7 @@ jobs: if: contains(matrix.image, 'ubuntu') run: | apt-get update - apt-get install -y cmake g++ make libxml2-utils libpcre3-dev + apt-get install -y cmake g++ make libxml2-utils libpcre2-dev - name: Install missing software (gui) on latest ubuntu if: contains(matrix.image, 'ubuntu') @@ -61,7 +61,7 @@ jobs: - name: Install missing software on Alpine if: contains(matrix.image, 'alpine') run: | - apk add cmake make g++ pcre-dev + apk add cmake make g++ pcre2-dev # needs to be called after the package installation since # - it doesn't call "apt-get update" @@ -104,12 +104,12 @@ jobs: if: contains(matrix.image, 'ubuntu') run: | apt-get update - apt-get install -y g++ make python3 libxml2-utils libpcre3-dev + apt-get install -y g++ make python3 libxml2-utils libpcre2-dev - name: Install missing software on Alpine if: contains(matrix.image, 'alpine') run: | - apk add make g++ pcre-dev bash python3 libxml2-utils + apk add make g++ pcre2-dev bash python3 libxml2-utils # needs to be called after the package installation since # - it doesn't call "apt-get update" diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index b172327d18b..b739e008c26 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -52,8 +52,7 @@ jobs: - name: Install missing software on macos if: contains(matrix.os, 'macos') run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 tinyxml2 pcre + brew install coreutils qt@6 tinyxml2 pcre2 - name: CMake build on ubuntu (with GUI / system tinyxml2) if: contains(matrix.os, 'ubuntu') @@ -121,8 +120,7 @@ jobs: - name: Install missing software on macos if: contains(matrix.os, 'macos') run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 pcre + brew install coreutils qt@6 pcre2 - name: Run CMake on ubuntu (with GUI) if: contains(matrix.os, 'ubuntu') @@ -238,8 +236,7 @@ jobs: - name: Install missing software on macos if: contains(matrix.os, 'macos') run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 pcre + brew install coreutils qt@6 pcre2 - name: Run CMake on ubuntu (with GUI) if: contains(matrix.os, 'ubuntu') @@ -486,8 +483,7 @@ jobs: - name: Install missing software on macos if: contains(matrix.os, 'macos') run: | - # pcre was removed from runner images in November 2022 - brew install coreutils pcre gnu-sed + brew install coreutils pcre2 gnu-sed - name: Install missing Python packages on ubuntu if: contains(matrix.os, 'ubuntu') diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 66858c7afbe..ced02f07d51 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -150,9 +150,8 @@ jobs: runs-on: ${{ matrix.os }} env: - # see https://www.pcre.org/original/changelog.txt - PCRE_VERSION: 8.45 - + # see https://github.com/PCRE2Project/pcre2/blob/master/ChangeLog + PCRE2_VERSION: 10.49 steps: - uses: actions/checkout@v6 with: @@ -170,32 +169,31 @@ jobs: with: arch: x64 - - name: Cache PCRE - id: cache-pcre + - name: Cache PCRE2 + id: cache-pcre2 uses: actions/cache@v5 with: path: | - externals\pcre.h - externals\pcre.lib - externals\pcre64.lib - key: pcre-${{ env.PCRE_VERSION }}-x64-bin-win + externals\pcre2.h + externals\pcre2-8.lib + key: pcre2-${{ env.PCRE2_VERSION }}-x64-bin-win - - name: Download PCRE - if: steps.cache-pcre.outputs.cache-hit != 'true' + - name: Download PCRE2 + if: steps.cache-pcre2.outputs.cache-hit != 'true' run: | - curl -fsSL https://github.com/pfultz2/pcre/archive/refs/tags/%PCRE_VERSION%.zip -o pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! + curl -fsSL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-%PCRE2_VERSION%/pcre2-%PCRE2_VERSION%.zip -o pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel! - - name: Install PCRE - if: steps.cache-pcre.outputs.cache-hit != 'true' + - name: Install PCRE2 + if: steps.cache-pcre2.outputs.cache-hit != 'true' run: | @echo on - 7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! - cd pcre-%PCRE_VERSION% || 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 -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - nmake || exit /b !errorlevel! - copy pcre.h ..\externals || exit /b !errorlevel! - copy pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel! + 7z x pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel! + cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel! + cmake -S . -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=Off -DBUILD_STATIC_LIBS=On -DPCRE2_SUPPORT_JIT=On -DPCRE2_BUILD_PCRE2GREP=Off -DPCRE2_BUILD_TESTS=Off || exit /b !errorlevel! + cmake --build build || exit /b !errorlevel! + cmake --install build --prefix install || exit /b !errorlevel! + copy install\include\pcre2.h ..\externals || exit /b !errorlevel! + copy install\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! env: CL: /MP diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 4f2db4ab113..568a16ba06d 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -35,7 +35,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y cmake make - sudo apt-get install -y libpcre3-dev + sudo apt-get install -y libpcre2-dev sudo apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake - name: Install clang diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 2e54b92541e..e583eb81e46 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -47,7 +47,7 @@ jobs: if: contains(matrix.image, 'debian') run: | apt-get update - apt-get install -y cmake clang make libpcre3-dev + apt-get install -y cmake clang make libpcre2-dev apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake apt-get install -y iwyu @@ -56,7 +56,7 @@ jobs: run: | set -x pacman -Sy - pacman -S cmake make clang pcre --noconfirm + pacman -S cmake make clang pcre2 --noconfirm pacman -S libglvnd --noconfirm # fixes missing dependency for Qt in CMake pacman-key --init pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com @@ -88,7 +88,7 @@ jobs: - name: Install missing software on OpenSUSE if: contains(matrix.image, 'opensuse') run: | - zypper install -y cmake clang pcre-devel + zypper install -y cmake clang pcre2-devel zypper install -y include-what-you-use-tools ln -s iwyu_tool.py /usr/bin/iwyu_tool @@ -96,7 +96,7 @@ jobs: - name: Install missing software on macOS if: contains(matrix.os, 'macos') run: | - brew install include-what-you-use pcre coreutils + brew install include-what-you-use pcre2 coreutils # on Apple Silicon files are symlinked under /opt/homebrew/bin ln -s /opt/homebrew/bin/iwyu_tool.py /usr/local/bin/iwyu_tool @@ -206,7 +206,7 @@ jobs: - name: Install missing software run: | sudo apt-get update - sudo apt-get install -y cmake make libpcre3-dev + sudo apt-get install -y cmake make libpcre2-dev sudo apt-get install -y libgl-dev # missing dependency for using Qt in CMake - name: Install clang diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index aa467d7b875..76e0b1939ca 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -26,8 +26,8 @@ jobs: env: PYTHON_VERSION: 3.14 - # see https://www.pcre.org/original/changelog.txt - PCRE_VERSION: 8.45 + # see https://github.com/PCRE2Project/pcre2/blob/master/ChangeLog + PCRE2_VERSION: 10.49 QT_VERSION: 6.10.0 BOOST_MINOR_VERSION: 89 @@ -45,20 +45,20 @@ jobs: - name: Set up Visual Studio environment uses: ilammy/msvc-dev-cmd@v1 - - name: Download PCRE + - name: Download PCRE2 run: | - curl -fsSL https://github.com/pfultz2/pcre/archive/refs/tags/%PCRE_VERSION%.zip -o pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! + curl -fsSL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-%PCRE2_VERSION%/pcre2-%PCRE2_VERSION%.zip -o pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel! - - name: Install PCRE + - name: Install PCRE2 run: | @echo on - 7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! - cd pcre-%PCRE_VERSION% || exit /b !errorlevel! - git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel! - cmake . -A x64 -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - msbuild -m PCRE.slnx -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! + 7z x pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel! + cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel! + cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF || exit /b !errorlevel! + cmake --build build --config Release || exit /b !errorlevel! + cmake --install build --config Release --prefix install || exit /b !errorlevel! + copy install\include\pcre2.h ..\externals || exit /b !errorlevel! + copy install\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! - name: Download Boost run: | diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 9d5a6007a69..f7a0aa75201 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -68,7 +68,7 @@ jobs: - name: Install missing software on ubuntu run: | sudo apt-get update - sudo apt-get install -y cmake make libpcre3-dev libboost-container-dev libxml2-utils + sudo apt-get install -y cmake make libpcre2-dev libboost-container-dev libxml2-utils sudo apt-get install -y libcups2-dev # required for Qt6PrintSupport in CMake since Qt 6.7.3 - name: Install clang diff --git a/.gitignore b/.gitignore index a821204bf2d..9dd585fcac9 100644 --- a/.gitignore +++ b/.gitignore @@ -126,6 +126,6 @@ stage # ccache folder in CI /.ccache -# PCRE Windows files -/externals/pcre.h -/externals/pcre64.lib +# PCRE2 Windows files +/externals/pcre2.h +/externals/pcre2-8.lib diff --git a/Makefile b/Makefile index 6f86e205f77..5fcb5479d37 100644 --- a/Makefile +++ b/Makefile @@ -140,16 +140,16 @@ ifeq (g++, $(findstring g++,$(CXX))) endif override CXXFLAGS += -std=c++11 ifeq ($(HAVE_RULES),yes) - PCRE_CONFIG = $(shell which pcre-config) + PCRE_CONFIG = $(shell which pcre2-config) ifeq ($(PCRE_CONFIG),) - $(error Did not find pcre-config) + $(error Did not find pcre2-config) endif override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags) override CPPFLAGS += -DHAVE_RULES ifdef LIBS - LIBS += $(shell $(PCRE_CONFIG) --libs) + LIBS += $(shell $(PCRE_CONFIG) --libs8) else - LIBS=$(shell $(PCRE_CONFIG) --libs) + LIBS=$(shell $(PCRE_CONFIG) --libs8) endif else ifneq ($(HAVE_RULES),) $(error invalid HAVE_RULES value '$(HAVE_RULES)') diff --git a/build-pcre.txt b/build-pcre.txt index 9f4e8e06e29..15ae68c463b 100644 --- a/build-pcre.txt +++ b/build-pcre.txt @@ -1,5 +1,5 @@ -PCRE is a library that is used by the optional "rules" feature for the command -line version of cppcheck. It is readily available on Linux and Mac OS X, but +PCRE2 is a library that is used by the optional "rules" feature for the command +line version of cppcheck. It is readily available on Linux and macOS, but must be obtained separately for Windows. Build instructions @@ -10,26 +10,17 @@ Windows Visual Studio -To build PCRE, download the source code from www.pcre.org and -CMake (https://cmake.org/download/). We assume you use Visual Studio 2015 - -otherwise adapt the commands for your version. +Download the PCRE2 source code from https://github.com/PCRE2Project/pcre2/releases +and CMake (https://cmake.org/download/). Then build a static library from a +Visual Studio developer command prompt: -VS Solution file - cmake . -G "Visual Studio 14 2015" - Open PCRE.sln with VS IDE or via cmd: - call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86 - MSBuild PCRE.sln /target:Build /property:Configuration="Release" + cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF + cmake --build build --config Release + cmake --install build --config Release --prefix install - For 64-bit target: cmake . -G "Visual Studio 14 2015 Win64" - -or using NMake - call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86 - cmake . -G "NMake Makefiles" - nmake - -or using MSYS - cmake . -G "MSYS Makefiles" - make +Copy install\include\pcre2.h and install\lib\pcre2-8-static.lib (renamed to +pcre2-8.lib) into the /externals directory and select the "Release-PCRE" or +"Debug-PCRE" configuration in cppcheck.sln. Linux @@ -37,27 +28,19 @@ Linux The normal Makefile should work. -Install PCRE on Ubuntu might be needed: - sudo apt-get install libpcre3 libpcre3-dev +Install PCRE2 on Debian/Ubuntu might be needed: + sudo apt-get install libpcre2-dev Mac OSX ------- -Install PCRE: - -homebre - brew install pcre - -or macport - sudo port install pcre - -Ensure /path/to/pcre.h is in CXXFLAGS, e.g: +Install PCRE2: -for homebrew - export CXXFLAGS=${CXXFLAGS}:/usr/local/include +homebrew + brew install pcre2 -or macport - export CXXFLAGS=${CXXFLAGS}:/opt/local/include +or macports + sudo port install pcre2 -Or for MSVC copy pcre.lib and pcre.h in /externals directory. +The Makefile uses pcre2-config to find the include and library paths. diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 842d597b0a4..3a1b5ac1e6f 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -2132,7 +2132,7 @@ void CmdLineParser::printHelp() const "Many thanks to the 3rd party libraries we use:\n" " * tinyxml2 -- loading project/library/ctu files.\n" " * picojson -- loading compile database.\n" - " * pcre -- rules.\n" + " * pcre2 -- rules.\n" " * qt -- used in GUI\n"; mLogger.printRaw(oss.str()); diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index b1f6571504d..4e8742d20d3 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -29,10 +29,10 @@ if(BUILD_GUI) endif() if(HAVE_RULES) - find_path(PCRE_INCLUDE pcre.h) - find_library(PCRE_LIBRARY NAMES pcre pcred) + find_path(PCRE_INCLUDE pcre2.h) + find_library(PCRE_LIBRARY NAMES pcre2-8 pcre2-8d pcre2-8-static pcre2-8-staticd) if(NOT PCRE_LIBRARY OR NOT PCRE_INCLUDE) - message(FATAL_ERROR "pcre dependency for RULES has not been found") + message(FATAL_ERROR "pcre2 dependency for RULES has not been found") endif() else() set(PCRE_LIBRARY "") diff --git a/cmake/options.cmake b/cmake/options.cmake index bda080fe77b..f03f422eeb6 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -94,7 +94,7 @@ if(NOT BUILD_GUI) endif() endif() -option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF) +option(HAVE_RULES "Usage of rules (needs PCRE2 library and headers)" OFF) option(USE_BUNDLED_TINYXML2 "Usage of bundled TinyXML2 library" ON) if(BUILD_CORE_DLL AND NOT USE_BUNDLED_TINYXML2) message(FATAL_ERROR "Cannot use external TinyXML2 library when building lib as DLL") diff --git a/externals/pcre.patch b/externals/pcre.patch deleted file mode 100644 index bf23435c934..00000000000 --- a/externals/pcre.patch +++ /dev/null @@ -1,12 +0,0 @@ -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/lib/cppcheck.vcxproj b/lib/cppcheck.vcxproj index 6957309e40f..c2484ebbcee 100644 --- a/lib/cppcheck.vcxproj +++ b/lib/cppcheck.vcxproj @@ -318,7 +318,7 @@ if exist "$(OutDir)platforms\unix64-unsigned.xml" del /q "$(OutDir)platforms\uni /Zc:throwingNew /Zc:__cplusplus %(AdditionalOptions) - pcre64.lib;%(AdditionalDependencies) + pcre2-8.lib;%(AdditionalDependencies) ../externals;%(AdditionalLibraryDirectories) true true @@ -403,7 +403,7 @@ if exist "$(OutDir)platforms\unix64-unsigned.xml" del /q "$(OutDir)platforms\uni stdcpp14 - pcre64.lib;%(AdditionalDependencies) + pcre2-8.lib;%(AdditionalDependencies) ../externals;%(AdditionalLibraryDirectories) true true diff --git a/lib/regex.cpp b/lib/regex.cpp index 3a94b293ed5..62156a9c320 100644 --- a/lib/regex.cpp +++ b/lib/regex.cpp @@ -20,141 +20,23 @@ #include "regex.h" +#include #include +#define PCRE2_CODE_UNIT_WIDTH 8 #ifdef _WIN32 -#define PCRE_STATIC +#define PCRE2_STATIC #endif -#include +#include namespace { - std::string pcreErrorCodeToString(const int pcreExecRet) + std::string pcre2ErrorToString(const int errorcode) { - switch (pcreExecRet) { - case PCRE_ERROR_NULL: - return "Either code or subject was passed as NULL, or ovector was NULL " - "and ovecsize was not zero (PCRE_ERROR_NULL)"; - case PCRE_ERROR_BADOPTION: - return "An unrecognized bit was set in the options argument (PCRE_ERROR_BADOPTION)"; - case PCRE_ERROR_BADMAGIC: - return "PCRE stores a 4-byte \"magic number\" at the start of the compiled code, " - "to catch the case when it is passed a junk pointer and to detect when a " - "pattern that was compiled in an environment of one endianness is run in " - "an environment with the other endianness. This is the error that PCRE " - "gives when the magic number is not present (PCRE_ERROR_BADMAGIC)"; - case PCRE_ERROR_UNKNOWN_NODE: - return "While running the pattern match, an unknown item was encountered in the " - "compiled pattern. This error could be caused by a bug in PCRE or by " - "overwriting of the compiled pattern (PCRE_ERROR_UNKNOWN_NODE)"; - case PCRE_ERROR_NOMEMORY: - return "If a pattern contains back references, but the ovector that is passed " - "to pcre_exec() is not big enough to remember the referenced substrings, " - "PCRE gets a block of memory at the start of matching to use for this purpose. " - "If the call via pcre_malloc() fails, this error is given. The memory is " - "automatically freed at the end of matching. This error is also given if " - "pcre_stack_malloc() fails in pcre_exec(). " - "This can happen only when PCRE has been compiled with " - "--disable-stack-for-recursion (PCRE_ERROR_NOMEMORY)"; - case PCRE_ERROR_NOSUBSTRING: - return "This error is used by the pcre_copy_substring(), pcre_get_substring(), " - "and pcre_get_substring_list() functions (see below). " - "It is never returned by pcre_exec() (PCRE_ERROR_NOSUBSTRING)"; - case PCRE_ERROR_MATCHLIMIT: - return "The backtracking limit, as specified by the match_limit field in a pcre_extra " - "structure (or defaulted) was reached. " - "See the description above (PCRE_ERROR_MATCHLIMIT)"; - case PCRE_ERROR_CALLOUT: - return "This error is never generated by pcre_exec() itself. " - "It is provided for use by callout functions that want to yield a distinctive " - "error code. See the pcrecallout documentation for details (PCRE_ERROR_CALLOUT)"; - case PCRE_ERROR_BADUTF8: - return "A string that contains an invalid UTF-8 byte sequence was passed as a subject, " - "and the PCRE_NO_UTF8_CHECK option was not set. If the size of the output vector " - "(ovecsize) is at least 2, the byte offset to the start of the the invalid UTF-8 " - "character is placed in the first element, and a reason code is placed in the " - "second element. The reason codes are listed in the following section. For " - "backward compatibility, if PCRE_PARTIAL_HARD is set and the problem is a truncated " - "UTF-8 character at the end of the subject (reason codes 1 to 5), " - "PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8"; - case PCRE_ERROR_BADUTF8_OFFSET: - return "The UTF-8 byte sequence that was passed as a subject was checked and found to " - "be valid (the PCRE_NO_UTF8_CHECK option was not set), but the value of " - "startoffset did not point to the beginning of a UTF-8 character or the end of " - "the subject (PCRE_ERROR_BADUTF8_OFFSET)"; - case PCRE_ERROR_PARTIAL: - return "The subject string did not match, but it did match partially. See the " - "pcrepartial documentation for details of partial matching (PCRE_ERROR_PARTIAL)"; - case PCRE_ERROR_BADPARTIAL: - return "This code is no longer in use. It was formerly returned when the PCRE_PARTIAL " - "option was used with a compiled pattern containing items that were not supported " - "for partial matching. From release 8.00 onwards, there are no restrictions on " - "partial matching (PCRE_ERROR_BADPARTIAL)"; - case PCRE_ERROR_INTERNAL: - return "An unexpected internal error has occurred. This error could be caused by a bug " - "in PCRE or by overwriting of the compiled pattern (PCRE_ERROR_INTERNAL)"; - case PCRE_ERROR_BADCOUNT: - return "This error is given if the value of the ovecsize argument is negative " - "(PCRE_ERROR_BADCOUNT)"; - case PCRE_ERROR_RECURSIONLIMIT: - return "The internal recursion limit, as specified by the match_limit_recursion " - "field in a pcre_extra structure (or defaulted) was reached. " - "See the description above (PCRE_ERROR_RECURSIONLIMIT)"; - case PCRE_ERROR_DFA_UITEM: - return "PCRE_ERROR_DFA_UITEM"; - case PCRE_ERROR_DFA_UCOND: - return "PCRE_ERROR_DFA_UCOND"; - case PCRE_ERROR_DFA_WSSIZE: - return "PCRE_ERROR_DFA_WSSIZE"; - case PCRE_ERROR_DFA_RECURSE: - return "PCRE_ERROR_DFA_RECURSE"; - case PCRE_ERROR_NULLWSLIMIT: - return "PCRE_ERROR_NULLWSLIMIT"; - case PCRE_ERROR_BADNEWLINE: - return "An invalid combination of PCRE_NEWLINE_xxx options was " - "given (PCRE_ERROR_BADNEWLINE)"; - case PCRE_ERROR_BADOFFSET: - return "The value of startoffset was negative or greater than the length " - "of the subject, that is, the value in length (PCRE_ERROR_BADOFFSET)"; - case PCRE_ERROR_SHORTUTF8: - return "This error is returned instead of PCRE_ERROR_BADUTF8 when the subject " - "string ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD option is set. " - "Information about the failure is returned as for PCRE_ERROR_BADUTF8. " - "It is in fact sufficient to detect this case, but this special error code for " - "PCRE_PARTIAL_HARD precedes the implementation of returned information; " - "it is retained for backwards compatibility (PCRE_ERROR_SHORTUTF8)"; - case PCRE_ERROR_RECURSELOOP: - return "This error is returned when pcre_exec() detects a recursion loop " - "within the pattern. Specifically, it means that either the whole pattern " - "or a subpattern has been called recursively for the second time at the same " - "position in the subject string. Some simple patterns that might do this " - "are detected and faulted at compile time, but more complicated cases, " - "in particular mutual recursions between two different subpatterns, " - "cannot be detected until run time (PCRE_ERROR_RECURSELOOP)"; - case PCRE_ERROR_JIT_STACKLIMIT: - return "This error is returned when a pattern that was successfully studied " - "using a JIT compile option is being matched, but the memory available " - "for the just-in-time processing stack is not large enough. See the pcrejit " - "documentation for more details (PCRE_ERROR_JIT_STACKLIMIT)"; - case PCRE_ERROR_BADMODE: - return "This error is given if a pattern that was compiled by the 8-bit library " - "is passed to a 16-bit or 32-bit library function, or vice versa (PCRE_ERROR_BADMODE)"; - case PCRE_ERROR_BADENDIANNESS: - return "This error is given if a pattern that was compiled and saved is reloaded on a " - "host with different endianness. The utility function pcre_pattern_to_host_byte_order() " - "can be used to convert such a pattern so that it runs on the new host (PCRE_ERROR_BADENDIANNESS)"; - case PCRE_ERROR_DFA_BADRESTART: - return "PCRE_ERROR_DFA_BADRESTART"; -#if PCRE_MAJOR >= 8 && PCRE_MINOR >= 32 - case PCRE_ERROR_BADLENGTH: - return "This error is given if pcre_exec() is called with a negative value for the length argument (PCRE_ERROR_BADLENGTH)"; - case PCRE_ERROR_JIT_BADOPTION: - return "This error is returned when a pattern that was successfully studied using a JIT compile " - "option is being matched, but the matching mode (partial or complete match) does not correspond " - "to any JIT compilation mode. When the JIT fast path function is used, this error may be " - "also given for invalid options. See the pcrejit documentation for more details (PCRE_ERROR_JIT_BADOPTION)"; -#endif - } - return "unknown PCRE error " + std::to_string(pcreExecRet); + PCRE2_UCHAR buffer[256]; + // a truncated message (PCRE2_ERROR_NOMEMORY) is still zero-terminated + if (pcre2_get_error_message(errorcode, buffer, sizeof(buffer)) == PCRE2_ERROR_BADDATA) + return "unknown PCRE2 error " + std::to_string(errorcode); + return reinterpret_cast(buffer); } class PcreRegex : public Regex @@ -166,16 +48,12 @@ namespace { ~PcreRegex() override { - if (mExtra) { - pcre_free_study(mExtra); - mExtra = nullptr; - } - if (mRe) { - pcre_free(mRe); - mRe = nullptr; - } + pcre2_code_free(mRe); } + PcreRegex(const PcreRegex&) = delete; + PcreRegex& operator=(const PcreRegex&) = delete; + std::string compile(); std::string match(const std::string& str, const MatchFn& matchFn) const override; @@ -185,8 +63,7 @@ namespace { private: std::string mPattern; - pcre* mRe{}; - pcre_extra* mExtra{}; + pcre2_code* mRe{}; }; std::string PcreRegex::compile() @@ -194,29 +71,14 @@ namespace { if (mRe) return "regular expression has already been compiled"; - const char *pcreCompileErrorStr = nullptr; - int erroffset = 0; - pcre * const re = pcre_compile(mPattern.c_str(),0,&pcreCompileErrorStr,&erroffset,nullptr); - if (!re) { - if (pcreCompileErrorStr) - return pcreCompileErrorStr; - return "unknown error"; - } + int errorcode = 0; + PCRE2_SIZE erroroffset = 0; + pcre2_code * const re = pcre2_compile(reinterpret_cast(mPattern.c_str()), mPattern.size(), 0, &errorcode, &erroroffset, nullptr); + if (!re) + return pcre2ErrorToString(errorcode); - // Optimize the regex, but only if PCRE_CONFIG_JIT is available -#ifdef PCRE_CONFIG_JIT - const char *pcreStudyErrorStr = nullptr; - pcre_extra * const pcreExtra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, &pcreStudyErrorStr); - // pcre_study() returns NULL for both errors and when it can not optimize the regex. - // The last argument is how one checks for errors. - // It is NULL if everything works, and points to an error string otherwise. - if (pcreStudyErrorStr) { - // pcre_compile() worked, but pcre_study() returned an error. Free the resources allocated by pcre_compile(). - pcre_free(re); - return std::string(pcreStudyErrorStr) + " (pcre_study)"; - } - mExtra = pcreExtra; -#endif + // JIT compilation is only an optimization - if it is not available the interpreter is used + (void)pcre2_jit_compile(re, PCRE2_JIT_COMPLETE); mRe = re; @@ -228,22 +90,29 @@ namespace { if (!mRe) return "regular expression has not been compiled yet"; - int pos = 0; - int ovector[30]= {0}; - while (pos < static_cast(str.size())) { - const int pcreExecRet = pcre_exec(mRe, mExtra, str.c_str(), static_cast(str.size()), pos, 0, ovector, 30); - if (pcreExecRet == PCRE_ERROR_NOMATCH) + // the match data is created per call since a Regex may be shared between threads + const std::unique_ptr matchData(pcre2_match_data_create_from_pattern(mRe, nullptr), &pcre2_match_data_free); + if (!matchData) + return "failed to allocate PCRE2 match data"; + + const auto subject = reinterpret_cast(str.c_str()); + const PCRE2_SIZE length = str.size(); + PCRE2_SIZE pos = 0; + while (pos < length) { + const int rc = pcre2_match(mRe, subject, length, pos, 0, matchData.get(), nullptr); + if (rc == PCRE2_ERROR_NOMATCH) return ""; - if (pcreExecRet < 0) { - return pcreErrorCodeToString(pcreExecRet) + " (pos: " + std::to_string(pos) + ")"; - } - const auto pos1 = static_cast(ovector[0]); - const auto pos2 = static_cast(ovector[1]); + if (rc < 0) + return pcre2ErrorToString(rc) + " (pos: " + std::to_string(pos) + ")"; + + const PCRE2_SIZE * const ovector = pcre2_get_ovector_pointer(matchData.get()); + const PCRE2_SIZE pos1 = ovector[0]; + const PCRE2_SIZE pos2 = ovector[1]; - matchFn(pos1, pos2); + matchFn(static_cast(pos1), static_cast(pos2)); - // jump to the end of the match for the next pcre_exec - pos = static_cast(pos2); + // continue at the end of the match - step forward on an empty match to avoid an endless loop + pos = (pos2 > pos) ? pos2 : (pos + 1); } return ""; diff --git a/man/writing-rules-1.docbook b/man/writing-rules-1.docbook index 26936d26b95..77eca34c43b 100644 --- a/man/writing-rules-1.docbook +++ b/man/writing-rules-1.docbook @@ -49,10 +49,10 @@
Step 1 - Creating the regular expression - Cppcheck uses the PCRE library to handle regular expressions. + Cppcheck uses the PCRE2 library to handle regular expressions. PCRE stands for "Perl Compatible Regular Expressions". - The homepage for PCRE is - http://www.pcre.org/. + The homepage for PCRE2 is + https://www.pcre.org/. Let's create a regular expression that checks for code such as: diff --git a/readme.md b/readme.md index 6671fdd4827..01cd161bf07 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,7 @@ Cppcheck requires a C++ compiler with (partial) C++11 support. Minimum required To build the GUI application, you need to use the CMake build system. -When building the command line tool, [PCRE](http://www.pcre.org/) is optional. It is used if you build with rules. +When building the command line tool, [PCRE2](https://www.pcre.org/) is optional. It is used if you build with rules. There are multiple compilation choices: @@ -67,7 +67,7 @@ cmake --build build If you want to compile the GUI you can use the flag. `-DBUILD_GUI=ON` -For rules support (requires pcre) use the flag. +For rules support (requires PCRE2) use the flag. `-DHAVE_RULES=ON` For release builds it is recommended that you use: @@ -98,7 +98,7 @@ cmake --build build --config RelWithDebInfo Use the `cppcheck.sln` file. The file is configured for Visual Studio 2019, but the platform toolset can be changed easily to older or newer versions. The solution contains platform targets for both x86 and x64. -To compile with rules, select "`Release-PCRE`" or "`Debug-PCRE`" configuration. `pcre.lib` (`pcre64.lib` for x64 builds) and `pcre.h` are expected to be in `/externals` then. A current version of PCRE for Visual Studio can be obtained using [vcpkg](https://github.com/microsoft/vcpkg). +To compile with rules, select "`Release-PCRE`" or "`Debug-PCRE`" configuration. The static PCRE2 library `pcre2-8.lib` and `pcre2.h` are expected to be in `/externals` then. See `build-pcre.txt` for how to build them. ### Visual Studio (from command line) @@ -114,8 +114,7 @@ Cppcheck Official is an extension officially supported by the cppcheck team allo ### Qt Creator + MinGW -The PCRE dll is needed to build the CLI. It can be downloaded here: - +PCRE2 is needed to build the CLI with rules. See `build-pcre.txt`. ### GNU compilers @@ -152,7 +151,7 @@ g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml Specifies the folder where Cppcheck files (addons, cfg, platform) are installed to. * `HAVE_RULES=yes` - Enables rules (requires PCRE to be installed). + Enables rules (requires PCRE2 to be installed). * `CXXOPTS="-O2"` Enables most compiler optimizations. diff --git a/readmeja.md b/readmeja.md index 7299d61745c..2bdc6d65094 100644 --- a/readmeja.md +++ b/readmeja.md @@ -20,7 +20,7 @@ C++11に対応したコンパイラが利用できます。部分的にC++11に GUIも利用する場合、Qtライブラリが必要です。 -コマンドラインツールをビルドする場合、[PCRE](http://www.pcre.org/)はオプションです。これはルールを作成するために利用します。 +コマンドラインツールをビルドする場合、[PCRE2](https://www.pcre.org/)はオプションです。これはルールを作成するために利用します。 コンパイル上の選択肢がいくつかあります。 * cmake - クロスプラットフォームのビルドツール @@ -47,19 +47,18 @@ C++標準を指定する必要がある場合次のオプションを指定し CppcheckのGUIが必要な場合次のフラグを指定します。 -DBUILD_GUI=ON -pcreが必要になりますが、正規表現のルールサポートが必要な場合次のフラグを指定します。 +PCRE2が必要になりますが、正規表現のルールサポートが必要な場合次のフラグを指定します。 -DHAVE_RULES=ON ### Visual Studio cppcheck.slnファイルが利用できます。このファイルは、Visual Studio 2019向けです。しかし、このプラットフォームツールセットはこれより新しいバージョンまたは古いバージョン向けに変更できます。このソルーションには、プラットフォームターゲットとしてx86とx64があります。 -ルールをコンパイルするためには、"Release-PCRE" または "Debug-PCRE" 設定を選択してください。pcre.lib (または pcre64.lib x64ビルド向け) と pcre.h を /externals にコピーしてください。Visual Studio のための PCRE の最新バージョンは [vcpkg](https://github.com/microsoft/vcpkg) から取得できます。 +ルールをコンパイルするためには、"Release-PCRE" または "Debug-PCRE" 設定を選択してください。pcre2-8.lib と pcre2.h を /externals にコピーしてください。ビルド方法は build-pcre.txt を参照してください。 ### Qt Creator + MinGW -コマンドラインツールをビルドするには、PCRE.dllが必要です。これは以下のURLからダウンロードできます。: -http://software-download.name/pcre-library-windows/ +ルール機能付きでコマンドラインツールをビルドするには PCRE2 が必要です。build-pcre.txt を参照してください。 ### GNU make @@ -84,7 +83,7 @@ cppcheckの最適化にPythonを使用します。Token::Match パターンは cppcheckの設定ファイル(addon や cfg や platform)を置くディレクトリを指定します。 3. `HAVE_RULES=yes` -ルール機能の有効化 (ルール機能には PCRE が必要です)設定です。 +ルール機能の有効化 (ルール機能には PCRE2 が必要です)設定です。 4. `CXXOPTS="-O2 -DNDEBUG"` ほとんどのコンパイラの最適化オプション、cppcheckの内部デバッグコードの無効化、基本的なコンパイラ警告の有効化 @@ -100,7 +99,7 @@ g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml `--rule` や `--rule-file` を利用する場合、依存ライブラリが必要です。 ```shell -g++ -o cppcheck -std=c++11 -lpcre -DHAVE_RULES -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 -Ilib cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/*.cpp +g++ -o cppcheck -std=c++11 -lpcre2-8 -DHAVE_RULES -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 -Ilib cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/*.cpp ``` ### MinGW diff --git a/releasenotes.txt b/releasenotes.txt index 33fd4106800..e70c9230171 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -22,6 +22,8 @@ Import project: Infrastructure & dependencies: - Added arm64 platform files arm64-windows.xml, arm64-linux.xml and arm64-macos.xml (Apple Silicon). These describe the default setup for that OS. The arm64-wchar_t2.xml and arm64-wchar_t4.xml files are kept. +- The rules feature (HAVE_RULES) now uses PCRE2 instead of the discontinued PCRE library. Existing rule patterns + and rule files work unchanged. On Windows the Visual Studio project now expects pcre2-8.lib and pcre2.h in externals. Other: - diff --git a/requirements.txt b/requirements.txt index 2ecb430828a..c15089734c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11 +pcre2,https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.49/pcre2-10.49.tar.gz -H sha256:929f0b20e62879252a15886b06c89f1edef61a363cbd5826fb041080a5e557ae diff --git a/test/testregex.cpp b/test/testregex.cpp index f26a9fee4fa..79650e85e70 100644 --- a/test/testregex.cpp +++ b/test/testregex.cpp @@ -41,6 +41,7 @@ class TestRegExBase : public TestFixture { TEST_CASE(multimatch); TEST_CASE(partialmatch); TEST_CASE(exactmatch); + TEST_CASE(emptymatch); } #define assertRegex(...) assertRegex_(__FILE__, __LINE__, __VA_ARGS__) @@ -193,6 +194,23 @@ class TestRegExBase : public TestFixture { ASSERT_EQUALS(3, e); } + void emptymatch() const { + // must not loop forever on a pattern that can match an empty string + const auto r = assertRegex("b*"); + + std::list> matches; + auto f = [&](int start, int end) { + matches.emplace_back(start, end); + }; + + ASSERT_EQUALS("", r->match("ab", std::move(f))); + ASSERT_EQUALS(2, matches.size()); + ASSERT_EQUALS(0, matches.front().first); + ASSERT_EQUALS(0, matches.front().second); + ASSERT_EQUALS(1, matches.back().first); + ASSERT_EQUALS(2, matches.back().second); + } + // TODO: how to provoke a match() error? #undef assertRegex diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index f9e638385e7..88b3941143f 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -760,16 +760,16 @@ int main(int argc, char **argv) << "\n"; fout << "ifeq ($(HAVE_RULES),yes)\n" - << " PCRE_CONFIG = $(shell which pcre-config)\n" + << " PCRE_CONFIG = $(shell which pcre2-config)\n" << " ifeq ($(PCRE_CONFIG),)\n" - << " $(error Did not find pcre-config)\n" + << " $(error Did not find pcre2-config)\n" << " endif\n" << " override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)\n" << " override CPPFLAGS += -DHAVE_RULES\n" << " ifdef LIBS\n" - << " LIBS += $(shell $(PCRE_CONFIG) --libs)\n" + << " LIBS += $(shell $(PCRE_CONFIG) --libs8)\n" << " else\n" - << " LIBS=$(shell $(PCRE_CONFIG) --libs)\n" + << " LIBS=$(shell $(PCRE_CONFIG) --libs8)\n" << " endif\n" << "else ifneq ($(HAVE_RULES),)\n" << " $(error invalid HAVE_RULES value '$(HAVE_RULES)')\n" From ab7764c3a58187ff94862e5e18ca16a46f968f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 7 Nov 2026 21:41:12 +0100 Subject: [PATCH 2/3] Fix CI: clang-tidy qualified-auto and PCRE2 install prefix on Windows The PCRE2 source archive contains an INSTALL file, so on the case-insensitive Windows file system "install" cannot be used as install prefix directory. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI-windows.yml | 6 +++--- .github/workflows/release-windows.yml | 6 +++--- build-pcre.txt | 4 ++-- lib/regex.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index ced02f07d51..a3dcf6f4825 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -191,9 +191,9 @@ jobs: cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel! cmake -S . -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=Off -DBUILD_STATIC_LIBS=On -DPCRE2_SUPPORT_JIT=On -DPCRE2_BUILD_PCRE2GREP=Off -DPCRE2_BUILD_TESTS=Off || exit /b !errorlevel! cmake --build build || exit /b !errorlevel! - cmake --install build --prefix install || exit /b !errorlevel! - copy install\include\pcre2.h ..\externals || exit /b !errorlevel! - copy install\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! + cmake --install build --prefix pcre2-dist || exit /b !errorlevel! + copy pcre2-dist\include\pcre2.h ..\externals || exit /b !errorlevel! + copy pcre2-dist\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! env: CL: /MP diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 76e0b1939ca..04d1ba2732a 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -56,9 +56,9 @@ jobs: cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel! cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF || exit /b !errorlevel! cmake --build build --config Release || exit /b !errorlevel! - cmake --install build --config Release --prefix install || exit /b !errorlevel! - copy install\include\pcre2.h ..\externals || exit /b !errorlevel! - copy install\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! + cmake --install build --config Release --prefix pcre2-dist || exit /b !errorlevel! + copy pcre2-dist\include\pcre2.h ..\externals || exit /b !errorlevel! + copy pcre2-dist\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel! - name: Download Boost run: | diff --git a/build-pcre.txt b/build-pcre.txt index 15ae68c463b..0f7e5ccc7ae 100644 --- a/build-pcre.txt +++ b/build-pcre.txt @@ -16,9 +16,9 @@ Visual Studio developer command prompt: cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF cmake --build build --config Release - cmake --install build --config Release --prefix install + cmake --install build --config Release --prefix pcre2-dist -Copy install\include\pcre2.h and install\lib\pcre2-8-static.lib (renamed to +Copy pcre2-dist\include\pcre2.h and pcre2-dist\lib\pcre2-8-static.lib (renamed to pcre2-8.lib) into the /externals directory and select the "Release-PCRE" or "Debug-PCRE" configuration in cppcheck.sln. diff --git a/lib/regex.cpp b/lib/regex.cpp index 62156a9c320..8425384d7bf 100644 --- a/lib/regex.cpp +++ b/lib/regex.cpp @@ -95,7 +95,7 @@ namespace { if (!matchData) return "failed to allocate PCRE2 match data"; - const auto subject = reinterpret_cast(str.c_str()); + const auto * const subject = reinterpret_cast(str.c_str()); const PCRE2_SIZE length = str.size(); PCRE2_SIZE pos = 0; while (pos < length) { From e209e12bc6f3e0f66edc5f89bb173d33c83725c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Nov 2026 18:37:10 +0100 Subject: [PATCH 3/3] review --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c15089734c9..c5e761b971f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pcre2,https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.49/pcre2-10.49.tar.gz -H sha256:929f0b20e62879252a15886b06c89f1edef61a363cbd5826fb041080a5e557ae +pcre2,PCRE2Project/pcre2@pcre2-10.49 -H sha256:69d04dcddcf9e038aeae8f58b0c07ee5e08abb835ee8daa2bd6acee433dc112c