#47842 [NEW]: sscanf does not support 64-bit values
[email protected] ("signe at cothlamadh dot net")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
From: signe at cothlamadh dot net
Operating system: FreeBSD 64-bit, Linux 64-bit
PHP version: 5.2.9
PHP Bug Type: Unknown/Other Function
Bug description: sscanf does not support 64-bit values
Description:
------------
On 64-bit operating systems, printf()'s %d and %u formatting codes support
64-bit integers. sscanf, which supposedly uses the same code (and has the
same expected behavior) does not support 64-bit values.
Also, printf is not outputting accurate values when it reaches numbers
near the upper bounds of a 64-bit int.
Reproduce code:
---------------
<?php
sscanf("2147483647", '%d', $int);
echo "sscanf 32-bit signed int '2147483647' (2^31)-1 =
",$int,"\n";
sscanf("4294967295", '%u', $int);
echo "sscanf 32-bit unsign int '4294967295' (2^32)-1 =
",$int,"\n";
sscanf("9223372036854775807", '%d', $int);
echo "sscanf 64-bit signed int '9223372036854775807' (2^63)-1 =
",$int,"\n";
sscanf("18446744073709551615", '%u', $int);
echo "sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 =
",$int,"\n";
printf("printf 64-bit signed int '9223372036854775807' (2^63)-1 = %d\n",
9223372036854775807);
printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n",
18446744073709551615);
echo "\n(2^64)-1 - 100,000,000\n";
printf("printf 64-bit signed int '18446744073609551615' = %u\n",
18446744073609551615);
echo "Output is 257 greater than input\n";
?>
Expected result:
----------------
sscanf 32-bit signed int '2147483647' (2^31)-1 = 2147483647
sscanf 32-bit unsign int '4294967295' (2^32)-1 = 4294967295
sscanf 64-bit signed int '9223372036854775807' (2^63)-1 =
9223372036854775807
sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 =
18446744073709551615
printf 64-bit signed int '9223372036854775807' (2^63)-1 =
9223372036854775807
printf 64-bit signed int '18446744073709551615' (2^64)-1 =
18446744073709551615
Actual result:
--------------
sscanf 32-bit signed int '2147483647' (2^31)-1 = 2147483647
sscanf 32-bit unsign int '4294967295' (2^32)-1 = 4294967295
sscanf 64-bit signed int '9223372036854775807' (2^63)-1 = -1
sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 4294967295
printf 64-bit signed int '9223372036854775807' (2^63)-1 =
9223372036854775807
printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0
printf 64-bit signed int '18446744073609551615' ((2^64)-1 - 100000000) =
18446744073609551872
Output is 257 greater than input
--
Edit bug report at http://bugs.php.net/?id=47842&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47842&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47842&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47842&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47842&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47842&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47842&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47842&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47842&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47842&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47842&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47842&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47842&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47842&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47842&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47842&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47842&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47842&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47842&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47842&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47842&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47842&r=mysqlcfg