Re: cvs: php-src /ext/standard/tests/strings pack.phpt
| From: | David Soria Parra | Date: | Mon, 20 Nov 2006 17:45:28 +0000 |
| Subject: | Re: cvs: php-src /ext/standard/tests/strings pack.phpt | ||
| References: | 1 2 3 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-41649@lists.php.net to get a copy of this message | ||
Hi,
the diff looks strange, but its definatly an bug. The bug appears,
because the (*zval)->value.lval that holds the value e.g. (-4294967296)
gets an integer overflow if the value is -2147483648 or less. As the
long value on the x86_64 is 8byte long, it can handle values like
-4294967296. So the overflow doesn't appear and the cutoff of the last
4bytes to get an 4byte integer as requested by the N or I option,
produce an integer with the value 0.
To avoid that, we have simulate the overflow ourself if the size of long
is greater than the requested size (e.g. 4byte to pack an int).
I added an patch to do this.
Furthermore I added an check if the machine is big_endian AND long is
greater than int, we have to start copy not from the beginning of the
long value to put it into an int as php_pack currently does, but we have
to jump to the highest 4byte as they store the bytes 0-32 on big
endians. But i cannot check this.
Also I fixed a bug that was introduced by the patch yesterday. unpack
with option N expect an big_endian, but we check the "issigned" against
machine_endian_long_map. The check must be based on the big_endian map
as the integer we check is big_endian.
For me the tests work. Antony, can you check the patch?
David Soria Parra
dsp@php.net
Am Montag, den 20.11.2006, 12:03 -0500 schrieb Ilia Alshanetsky:
> Diff is a bit strange, for example identical values on the same lines
> are shown as being different...
>
>
> On 20-Nov-06, at 5:55 AM, Antony Dovgal wrote:
>
> > 100+ [1] => 65534
> > 100- [1] => 65534
>
> Ilia Alshanetsky
>
>
>
Attachment: [text/x-patch] pack.c.diff
Attachment: [text/x-patch] pack.c.diff