Bug #47842 [Opn->Csd]: sscanf() does not support 64-bit values
| From: | mike@php.net | Date: | Wed, 19 May 2010 11:28:32 +0000 |
| Subject: | Bug #47842 [Opn->Csd]: sscanf() does not support 64-bit values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150595@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=47842&edit=1
ID: 47842
Updated by: mike@php.net
Reported by: signe at cothlamadh dot net
Summary: sscanf() does not support 64-bit values
-Status: Open
+Status: Closed
Type: Bug
Package: Strings related
Operating System: * (64bit)
PHP Version: 5.2.9
-Assigned To:
+Assigned To: mike
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2010-05-19 13:28:12] mike@php.net
Automatic comment from SVN on behalf of mike
Revision: http://svn.php.net/viewvc/?view=revision&revision=299484
Log: * fixed bug #47842 sscanf() does not support 64-bit values
------------------------------------------------------------------------
[2009-03-30 22:09:53] signe at cothlamadh dot net
Note: sscanf %x and %X have the same behavior as %d and %u
------------------------------------------------------------------------
[2009-03-30 21:26:23] signe at cothlamadh dot net
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 this bug report at http://bugs.php.net/bug.php?id=47842&edit=1