From 7489fd3a8b716c75a804161a5ef568035d85403d Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 6 Mar 2026 23:07:21 -0500 Subject: [PATCH] Remove 32-bit limitation (#2388) * Remove 32-bit limitation * Fix build problems * Add 32-bit disclaimer and fix MSVC x86 warnings - Move 32-bit warning to top of README with strong disclaimer - Add static_cast to fix truncation warnings on 32-bit MSVC Co-Authored-By: Claude Opus 4.6 --------- Co-authored-by: Claude Opus 4.6 --- .github/workflows/test-32bit.yml | 36 ++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 5 ++--- CMakeLists.txt | 3 --- README.md | 3 +++ httplib.h | 25 +++------------------- test/test_32bit_build.cpp | 9 ++++++++ 6 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/test-32bit.yml create mode 100644 test/test_32bit_build.cpp diff --git a/.github/workflows/test-32bit.yml b/.github/workflows/test-32bit.yml new file mode 100644 index 0000000..2fa0337 --- /dev/null +++ b/.github/workflows/test-32bit.yml @@ -0,0 +1,36 @@ +name: 32-bit Build Test + +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + test-win32: + name: Windows 32-bit (MSVC x86) + runs-on: windows-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: Build (Win32) + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86 + cl /std:c++14 /EHsc /W4 /WX /c /Fo:NUL test\test_32bit_build.cpp + + test-arm32: + name: ARM 32-bit (cross-compile) + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: Install cross compiler + run: sudo apt-get update && sudo apt-get install -y g++-arm-linux-gnueabihf + - name: Build (ARM 32-bit) + run: arm-linux-gnueabihf-g++ -std=c++11 -Wall -Wextra -Wno-psabi -Werror -c -o /dev/null test/test_32bit_build.cpp diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 378c0ce..9bac545 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,7 +40,7 @@ jobs: clang-format --version cd test && make style_check - build-error-check-on-32bit: + build-and-test-on-32bit: runs-on: ubuntu-latest if: > (github.event_name == 'push') || @@ -64,9 +64,8 @@ jobs: libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \ zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }} \ libzstd-dev${{ matrix.config.arch_suffix }} - - name: build and run tests (expect failure) + - name: build and run tests run: cd test && make test EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}" - continue-on-error: true ubuntu: runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index ae236c3..1874e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,9 +173,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows") message(WARNING "The target is Windows but CMAKE_SYSTEM_VERSION is not set, the default system version is set to Windows 10.") endif() endif() -if(CMAKE_SIZEOF_VOID_P LESS 8) - message(WARNING "Pointer size ${CMAKE_SIZEOF_VOID_P} is not supported. Please use a 64-bit compiler.") -endif() # Set some variables that are used in-tree and while building based on our options set(HTTPLIB_IS_COMPILED ${HTTPLIB_COMPILE}) diff --git a/README.md b/README.md index 7ba3862..31934dc 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Learn more in the [official documentation](https://yhirose.github.io/cpp-httplib > [!IMPORTANT] > This library uses 'blocking' socket I/O. If you are looking for a library with 'non-blocking' socket I/O, this is not the one that you want. +> [!WARNING] +> 32-bit platforms are **NOT supported**. Use at your own risk. The library may compile on 32-bit targets, but no security review has been conducted for 32-bit environments. Integer truncation and other 32-bit-specific issues may exist. **Security reports that only affect 32-bit platforms will be closed without action.** The maintainer does not have access to 32-bit environments for testing or fixing issues. CI includes basic compile checks only, not functional or security testing. + ## Main Features - HTTP Server/Client diff --git a/httplib.h b/httplib.h index a920373..7070416 100644 --- a/httplib.h +++ b/httplib.h @@ -11,26 +11,6 @@ #define CPPHTTPLIB_VERSION "0.37.0" #define CPPHTTPLIB_VERSION_NUM "0x002500" -/* - * Platform compatibility check - */ - -#if defined(_WIN32) && !defined(_WIN64) -#if defined(_MSC_VER) -#pragma message( \ - "cpp-httplib doesn't support 32-bit Windows. Please use a 64-bit compiler.") -#else -#warning \ - "cpp-httplib doesn't support 32-bit Windows. Please use a 64-bit compiler." -#endif -#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ < 8 -#warning \ - "cpp-httplib doesn't support 32-bit platforms. Please use a 64-bit compiler." -#elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__ < 8 -#warning \ - "cpp-httplib doesn't support platforms where size_t is less than 64 bits." -#endif - #ifdef _WIN32 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00 #error \ @@ -2801,7 +2781,7 @@ inline size_t get_header_value_u64(const Headers &headers, std::advance(it, static_cast(id)); if (it != rng.second) { if (is_numeric(it->second)) { - return std::strtoull(it->second.data(), nullptr, 10); + return static_cast(std::strtoull(it->second.data(), nullptr, 10)); } else { is_invalid_value = true; } @@ -8241,7 +8221,8 @@ get_range_offset_and_length(Range r, size_t content_length) { assert(r.first <= r.second && r.second < static_cast(content_length)); (void)(content_length); - return std::make_pair(r.first, static_cast(r.second - r.first) + 1); + return std::make_pair(static_cast(r.first), + static_cast(r.second - r.first) + 1); } inline std::string make_content_range_header_field( diff --git a/test/test_32bit_build.cpp b/test/test_32bit_build.cpp new file mode 100644 index 0000000..c616e85 --- /dev/null +++ b/test/test_32bit_build.cpp @@ -0,0 +1,9 @@ +#include "../httplib.h" + +int main() { + httplib::Server svr; + httplib::Client cli("localhost", 8080); + (void)svr; + (void)cli; + return 0; +}