Skip to content

Commit f470162

Browse files
committed
Code Quality: Resolve the identical.alwaysFalse PHPStan errors.
In `wp_rand()` the `3000000000 === 2147483647` comparison was added in r21685 to detect misconfigured 32-bit PHP builds (Entropy PHP, for example) that truncate integer literals larger than `PHP_INT_MAX` instead of overflowing them to floats, so that `0xffffffff` could be built from a string cast to a float on them. PHPStan evaluates the literals as a 64-bit build does, so it reported the comparison as always false. It is replaced with a `PHP_INT_SIZE` check, which uses the explicit float on every 32-bit build. Behavior is unchanged, since on a correctly configured 32-bit build the literal already overflows to the same float. This empties the baseline, so it is removed. The `identical.alwaysFalse` ignore for `WP_HTML_Processor::step()` in `phpstan.neon.dist` remains, since that report is a false positive for the bookmark exhaustion guards added in r61755, which are intentional. Developed in #13782. Follow-up to r21685, r63023. Props arshidkv12, westonruter, mukesh27. See #66739. git-svn-id: https://develop.svn.wordpress.org/trunk@65792 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5601a21 commit f470162

2 files changed

Lines changed: 4 additions & 28 deletions

File tree

‎src/wp-includes/pluggable.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,10 +3054,11 @@ function wp_rand( $min = null, $max = null ) {
30543054
global $rnd_value;
30553055

30563056
/*
3057-
* Some misconfigured 32-bit environments (Entropy PHP, for example)
3058-
* truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
3057+
* On 32-bit systems, 0xffffffff exceeds PHP_INT_MAX, so it is cast to a float explicitly.
3058+
* Some misconfigured 32-bit environments (Entropy PHP, for example) truncate integer literals
3059+
* larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
30593060
*/
3060-
$max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff
3061+
$max_random_number = PHP_INT_SIZE === 4 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff
30613062

30623063
if ( null === $min ) {
30633064
$min = 0;

‎tests/phpstan/baselines/identical.alwaysFalse.neon‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)