Req #68480 [NEW]: unpack unsigned large number becoming negative
| From: | ignasimg at gmail dot com | Date: | Sat, 22 Nov 2014 12:07:58 +0000 |
| Subject: | Req #68480 [NEW]: unpack unsigned large number becoming negative | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-188744@lists.php.net to get a copy of this message | ||
From: ignasimg at gmail dot com
Operating system: Irrelevant
PHP version: Irrelevant
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:unpack unsigned large number becoming negative
Description:
------------
According to the documentation page about unpack:
http://php.net/manual/en/function.unpack.php
Caution
[...] If you unpack a large unsigned long and it is of the same size as
PHP internally stored values the result will be a negative number even
though unsigned unpacking was specified.
My question (beside wtf?) is would it be so hard to specify inside the
unpack function that if unsigned was required make it become unsigned?
I mean... it might sound stupidly ridicoulous but why is there an
unsigned format if it acts the same as with signed?
There's even some funny solution on the same page comments:
if ($unpackedVal <0)
{
$unpackedVal += 4294967296;
}
which is platform dependent and probably inefficient.
But since I have no idea about the inner workings of PHP my question
again is would it be so difficult to make it behave properly?
--
Edit bug report at https://bugs.php.net/bug.php?id=68480&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68480&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68480&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68480&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68480&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68480&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68480&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68480&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68480&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68480&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68480&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68480&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68480&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68480&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68480&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68480&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68480&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68480&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68480&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68480&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68480&r=mysqlcfg