Bug #75664 [NEW]: sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX

From: Date: Sun, 10 Dec 2017 23:35:09 +0000
Subject: Bug #75664 [NEW]: sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213046@lists.php.net to get a copy of this message
From: erik at evanv dot nl Operating system: linux 4.14.4 PHP version: 7.2.0 Package: Strings related Bug Type: Bug Bug description:sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX Description: ------------ Code speaks for itself. This can lead to data corruption. A decent solution would be to display unknown least significant digits as 0 just like %f. Alternative would be an ArithmeticError. Test script: --------------- php > $var = PHP_INT_MAX * 2; php > echo sprintf("%f", $var); 18446744073709551616.000000 php > echo sprintf("%u", $var); 0 Expected result: ---------------- 18446744073709551616 Actual result: -------------- 0 -- Edit bug report at https://bugs.php.net/bug.php?id=75664&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75664&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75664&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75664&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75664&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75664&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75664&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75664&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75664&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75664&r=support Expected behavior: https://bugs.php.net/fix.php?id=75664&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75664&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75664&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75664&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75664&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75664&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75664&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75664&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75664&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75664&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75664&r=mysqlcfg

« previous php.bugs (#213046) next »