Bug #72315 [Opn]: Unpack 'J' & 'P' doesn't produce expected results

From: Date: Thu, 02 Jun 2016 10:57:28 +0000
Subject: Bug #72315 [Opn]: Unpack 'J' & 'P' doesn't produce expected results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201402@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72315&edit=1 ID: 72315 User updated by: ads at tristanleboss dot net Reported by: ads at tristanleboss dot net Summary: Unpack 'J' & 'P' doesn't produce expected results Status: Open Type: Bug -Package: *Mail Related +Package: *Math Functions Operating System: Windows 7 x64 PHP Version: 7.0.7 Block user comment: N Private report: N New Comment: Package: Math functions Previous Comments: ------------------------------------------------------------------------ [2016-06-02 10:56:46] ads at tristanleboss dot net Description: ------------ Hello, While doing some tests, I discovered the 'P' format (unsigned long long (always 64 bit, little endian byte order)) and the 'J' format (unsigned long long (always 64 bit, big endian byte order)) are not giving the expected results on my Windows 7 x64 test machine with PHP 7.0.7RC1. Indeed, they don't account for the "unsigned" nature and output the signed version. Indeed: unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-8070445917020880704". The expected result is "13835331353480265872". unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-4611412720229285744". The expected result is "10376298156688670912". No error/warning message will be displayed. Test script: --------------- <?php var_dump( unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") ); var_dump( unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") ); Expected result: ---------------- array(1) { [1]=> int(13835331353480265872) } array(1) { [1]=> int(10376298156688670912) } Actual result: -------------- array(1) { [1]=> int(-8070445917020880704) } array(1) { [1]=> int(-4611412720229285744) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72315&edit=1

« previous php.bugs (#201402) next »