php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13339 sscanf returns wrong result
Submitted: 2001-09-17 05:50 UTC Modified: 2002-07-07 12:38 UTC
From: dev at generalprotectionfault dot de Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.6 OS: Windows NT 4.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dev at generalprotectionfault dot de
New email:
PHP Version: OS:

 

 [2001-09-17 05:50 UTC] dev at generalprotectionfault dot de
I've tried this:

list($x) = sscanf( 'ac100000', '%x' );
printf("%x",$x);

And I got "7fffffff", weird.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-17 05:53 UTC] derick@php.net
This is not weird, PHP's int are signed integers. 0xac00000 is too large for that.

Derick
 [2001-09-18 02:34 UTC] derick@php.net
Please use the Web system for answerring.

User update:
You said php4 uses signed integers, so please explain that:

// - - - - - - - - - - - - - - - - - -
list($x) = sscanf( 'ffffffff', '%x' );
printf("%x<br>",$x);

$x = pow(2,32)-1;
echo $x , "<br>";
$y = ( $x >> 16 ) & 0xFFFF ;
$x &= 0xFFFF;

printf("%x%x<br>",$y,$x);
// - - - - - - - - - - - - - - - - - -

Result:
7fffffff
4294967295
ffffffff
 [2001-09-18 02:35 UTC] derick@php.net
This was my result (On linux):
7ffffff
4294967295
80000
 [2002-07-07 12:38 UTC] derick@php.net
$x = pow(2,32)-1; var_dump ($x) will give this:

float(4294967295)

Which is not an integer, and thus the value can be larger than +(2^31 -1)

Anyway, this is not a bug, so closing.

Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 11:01:29 2025 UTC