#32700 [NEW]: unpack() returns signed values when it shouldn't

From: Date: Wed, 13 Apr 2005 20:49:33 +0000
Subject: #32700 [NEW]: unpack() returns signed values when it shouldn't
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-77481@lists.php.net to get a copy of this message
From: ieure@php.net Operating system: Linux PHP version: 4.3.10 PHP Bug Type: Unknown/Other Function Bug description: unpack() returns signed values when it shouldn't Description: ------------ unpack() returns signed long values when the high bit is set, even though the unpack format is set to unsigned long. Workaround: $foo = unpack('N', $data); $foo = $foo << 1 >> 1; $foo += 0x80000000; Reproduce code: --------------- // High bit is set. $before = 0x80000002; echo "Before: $before\n"; // Outputs '2147483650' $int = pack('N', $before); $res = unpack('N', $int); $after = $res[1]; echo "After: $after\n"; // Outputs '-2147483646' Expected result: ---------------- $before and $after should be the same number. Actual result: -------------- $after is treated as signed, and does not equal $before. Script output: Before: 2147483650 After: -2147483646 -- Edit bug report at http://bugs.php.net/?id=32700&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32700&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32700&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32700&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32700&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32700&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32700&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32700&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32700&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32700&r=support Expected behavior: http://bugs.php.net/fix.php?id=32700&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32700&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32700&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32700&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32700&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32700&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32700&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32700&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32700&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32700&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32700&r=mysqlcfg

« previous php.bugs (#77481) next »