cvs: php-src /ext/standard pack.c /ext/standard/tests/strings bug38770.phpt
| From: | Ilia Alshanetsky | Date: | Sun, 19 Nov 2006 18:21:50 +0000 |
| Subject: | cvs: php-src /ext/standard pack.c /ext/standard/tests/strings bug38770.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-41635@lists.php.net to get a copy of this message | ||
iliaa Sun Nov 19 18:21:50 2006 UTC
Modified files:
/php-src/ext/standard/tests/strings bug38770.phpt
/php-src/ext/standard pack.c
Log:
MFB: Fixed bug #38770 (unpack() broken with longs on 64 bit machines).
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/bug38770.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/bug38770.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/bug38770.phpt:1.2
--- /dev/null Sun Nov 19 18:21:50 2006
+++ php-src/ext/standard/tests/strings/bug38770.phpt Sun Nov 19 18:21:50 2006
@@ -0,0 +1,25 @@
+--TEST--
+Bug #38770 (unpack() broken with longs on 64 bit machines)
+--FILE--
+<?php
+
+foreach (array('N','I','l') as $v) {
+ print_r(unpack($v, pack($v, -30000)));
+}
+
+echo "Done\n";
+?>
+--EXPECT--
+Array
+(
+ [1] => -30000
+)
+Array
+(
+ [1] => -30000
+)
+Array
+(
+ [1] => -30000
+)
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/pack.c?r1=1.62&r2=1.63&diff_format=u
Index: php-src/ext/standard/pack.c
diff -u php-src/ext/standard/pack.c:1.62 php-src/ext/standard/pack.c:1.63
--- php-src/ext/standard/pack.c:1.62 Sun Feb 19 18:19:33 2006
+++ php-src/ext/standard/pack.c Sun Nov 19 18:21:50 2006
@@ -15,7 +15,7 @@
| Author: Chris Schneider <cschneid@relog.ch> |
+----------------------------------------------------------------------+
*/
-/* $Id: pack.c,v 1.62 2006/02/19 18:19:33 iliaa Exp $ */
+/* $Id: pack.c,v 1.63 2006/11/19 18:21:50 iliaa Exp $ */
#include "php.h"
@@ -752,14 +752,16 @@
case 'i':
case 'I': {
- long v;
+ long v = 0;
int issigned = 0;
if (type == 'i') {
issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80;
- }
+ } else if (sizeof(long) > 4 && (input[inputpos + machine_endian_long_map[3]] &
0x80) == 0x80) {
+ v = ~INT_MAX;
+ }
- v = php_unpack(&input[inputpos], sizeof(int), issigned, int_map);
+ v |= php_unpack(&input[inputpos], sizeof(int), issigned, int_map);
add_assoc_long(return_value, n, v);
break;
}
@@ -770,7 +772,7 @@
case 'V': {
int issigned = 0;
int *map = machine_endian_long_map;
- long v;
+ long v = 0;
if (type == 'l') {
issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80;
@@ -780,7 +782,11 @@
map = little_endian_long_map;
}
- v = php_unpack(&input[inputpos], 4, issigned, map);
+ if (sizeof(long) > 4 && (input[inputpos + machine_endian_long_map[3]] & 0x80)
== 0x80) {
+ v = ~INT_MAX;
+ }
+
+ v |= php_unpack(&input[inputpos], 4, issigned, map);
add_assoc_long(return_value, n, v);
break;
}