Commit: 4d8d5d83fce83c32a04cd8d8cf50d909ab101f38 Author: Remi Collet <r...@php.net> Tue, 11 Dec 2012 16:30:08 +0100 Parents: a9a5f7aca61d4bec9ce2cf5dc967bb7c0ed651cd Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38 Log: Fixed Bug #63738 unpack: back result with Z format Fix result for empty string. Same output as perl perl -e 'print unpack("Z2","\0\0");' => "" perl -e 'print unpack("Z2","A\0");' => "A" perl -e 'print unpack("Z2","AB\0");' => "AB" perl -e 'print unpack("Z2","ABC\0");'=> "AB" Bugs: https://bugs.php.net/63738 Changed paths: M ext/standard/pack.c M ext/standard/tests/strings/pack_Z.phpt Diff: diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 9894746..0472cb2 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -729,8 +729,7 @@ PHP_FUNCTION(unpack) size = len; /* Remove everything after the first null */ - s = 0; - while (s++ <= len) { + for (s=0 ; s < len ; s++) { if (input[inputpos + s] == pad) break; } diff --git a/ext/standard/tests/strings/pack_Z.phpt b/ext/standard/tests/strings/pack_Z.phpt index 8a2ee67..4fd007a 100644 --- a/ext/standard/tests/strings/pack_Z.phpt +++ b/ext/standard/tests/strings/pack_Z.phpt @@ -9,9 +9,15 @@ var_dump( pack("Z4", "foo"), pack("Z*", "foo"), unpack("Z*", "foo\0\rbar\0 \t\r\n"), - unpack("Z9", "foo\0\rbar\0 \t\r\n") + unpack("Z9", "foo\0\rbar\0 \t\r\n"), + unpack("Z2", "\0"), + unpack("Z2", "\0\0"), + unpack("Z2", "A\0"), + unpack("Z2", "AB\0"), + unpack("Z2", "ABC") ); --EXPECTF-- +Warning: unpack(): Type Z: not enough input, need 2, have 1 in %s on line %d string(0) "" string(5) "foo%c%c" string(4) "foo%c" @@ -25,3 +31,20 @@ array(1) { [1]=> string(3) "foo" } +bool(false) +array(1) { + [1]=> + string(0) "" +} +array(1) { + [1]=> + string(1) "A" +} +array(1) { + [1]=> + string(2) "AB" +} +array(1) { + [1]=> + string(2) "AB" +} -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php