[php-src] PR #25992: Enable -Wshorten-64-to-32 where the compiler supports it (clang)

From: Date: Tue, 01 Dec 2026 09:01:07 +0000
Subject: [php-src] PR #25992: Enable -Wshorten-64-to-32 where the compiler supports it (clang)
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41308@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25992 Author: marc-mabe Clang's -Wshorten-64-to-32 reports implicit conversions that drop the upper 32 bits, e.g. a zend_long or size_t stored in an int or uint32_t. This PR enables it in every build whose compiler supports it, as a warning only. ## Why Nothing reports these conversions today, so new ones keep being added unnoticed. Enabling it in the regular build makes it visible to anyone working on the code with clang, locally and in the clang CI jobs. ### A warning is not necessarily a bug The warning only says that a conversion is implicit, not that it is unchecked. Often the value is already range checked before it. A checked conversion warns exactly like an unchecked one, so today the safe and the unsafe cases look the same, and real truncation bugs hide among them. Fixing a warning therefore means: 1. make sure the value is range checked before the conversion (add the check if it is missing), then 2. convert it explicitly. Recent fixes this warning would have flagged before they were fixed: - #23555: gregoriantojd(1 + 2**32, 1, 1) returned the Julian Day of month 1 instead of 0. The *ToSdn() helpers took int, so the zend_long arguments were narrowed before any range check could run. The pre-fix calendar.c warns at every call site. - #22986 (GH-19320): FPM parsed numeric user, group, listen.owner and listen.group with strtoul() into int fields, so an out-of-range ID silently became a different ID before reaching setuid(), setgid() or chown(). The pre-fix fpm_unix.c warns on each of those assignments. ## What this PR does - Zend/Zend.m4: adds -Wshorten-64-to-32 -Wno-error=shorten-64-to-32 when the compiler accepts the flag. - The existing AX_CHECK_COMPILE_FLAG check compiles with -Werror, so GCC (which doesn't know the flag) silently skips it, without any "unknown warning option" noise. - -Wno-error= keeps --enable-werror builds working until the existing warnings are fixed. - ext/standard/password.c: an example fix as separate commit. The Argon2 costs and thread count are already range checked against limits that fit into uint32_t, so the conversions only need to be made explicit. No behaviour change. The bundled libraries get the warning as well. That may be useful for their upstreams, and the warning can be disabled per library if needed. ## Numbers The numbers are distinct file:line:col locations, so a warning in a header counts only once. | | arm64 | i386 | |---|---:|---:| | Zend | 537 | 9 | | main | 32 | 7 | | sapi | 107 | 2 | | ext | 1,232 | 117 | | libraries maintained in php-src (libbcmath, libcdb, libmbfl) | 8 | 0 | | bundled external libraries (libgd, timelib, PCRE2, IR, libmagic) | 185 | 88 | | **Total** | **2,101** | **223** | Fixing these existing warnings need separate, reviewable PRs, directory by directory. Where an existing check is missing, add it; where one exists, cast explicitly. If all warnings are fixed -Wno-error=shorten-64-to-32 may be dropped to make it an error.

« previous php.git-pulls (#41308) next »