ID:               47564
 Comment by:       vivekanandan8 at yahoo dot com
 Reported By:      laacz at laacz dot lv
 Status:           Open
 Bug Type:         Strings related
 Operating System: 6.1-STABLE FreeBSD (amd64)
 PHP Version:      5.2.9
 New Comment:

Hi,
   Generally the Zend engine holds any variable as  zval which holds
the integer as long data type only. 

32 bit Platform: long         => 4 byte = 32 bit 
64 bit Platform: long         => 8 byte = 64 bit
64 bit Platform: unsigned int => 4 byte = 32 bit

Hence in the 64 bit platform, we have to convert from long to unsigned
int only in 64 bit Platform.
Hence in php source  php5.3-200903301230/ext/standard/pack.c
In PHP_FUNCTION(unpack) place, add this convertion immediate
after  php_unpack function as folows. 

v |= php_unpack(&input[inputpos], 4, issigned, map);
if (sizeof(long) > 4) { v = (unsigned int) v; }


I tested in both 32 & 64 bit platform ,it works fine , please close
this Bug
Regards,
vivekanandan


Previous Comments:
------------------------------------------------------------------------

[2009-03-04 16:43:21] laacz at laacz dot lv

Description:
------------
Unpacking unsigned long (32bit; always big endian; "N") on 64bit 
system returns 64bit signed int instead of 32bit.

You can do & 0xffffffff on unpacked value, and get desired result, 
but that's still a bug.

Reproduce code:
---------------
<?php
list(,$command_id) =  unpack('N', chr(0x80) . chr(0x00) . chr(0x00) .
chr(0x09));
echo hexdec(dechex($command_id)) . "\n0x" . dechex($command_id) .
"\n";
?>



Expected result:
----------------
2147483657
0x80000009





Actual result:
--------------
1.8446744071562E+19
0xffffffff80000009






------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47564&edit=1

Reply via email to