Skip to content

Commit c1104b0

Browse files
author
Brian Shire
committed
MFB: correction for previous fix to bug #38770 (pack/unpack is broken on 64bit)
fix pack test, correct space to tabs
1 parent ab5d9f9 commit c1104b0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

ext/standard/pack.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ PHP_FUNCTION(unpack)
738738
issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80;
739739
} else if (sizeof(long) > 4 && (input[inputpos + machine_endian_long_map[3]] & 0x80) == 0x80) {
740740
v = ~INT_MAX;
741-
}
741+
}
742742

743743
v |= php_unpack(&input[inputpos], sizeof(int), issigned, int_map);
744744
add_assoc_long(return_value, n, v);
@@ -753,15 +753,17 @@ PHP_FUNCTION(unpack)
753753
int *map = machine_endian_long_map;
754754
long v = 0;
755755

756-
if (type == 'l') {
756+
if (type == 'l' || type == 'L') {
757757
issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80;
758758
} else if (type == 'N') {
759+
issigned = input[inputpos] & 0x80;
759760
map = big_endian_long_map;
760761
} else if (type == 'V') {
762+
issigned = input[inputpos + 3] & 0x80;
761763
map = little_endian_long_map;
762764
}
763765

764-
if (sizeof(long) > 4 && (input[inputpos + machine_endian_long_map[3]] & 0x80) == 0x80) {
766+
if (sizeof(long) > 4 && issigned) {
765767
v = ~INT_MAX;
766768
}
767769

ext/standard/tests/strings/pack.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Array
145145
)
146146
Array
147147
(
148-
[1] => 0
148+
[1] => -1
149149
)
150150
Array
151151
(
@@ -185,7 +185,7 @@ Array
185185
)
186186
Array
187187
(
188-
[1] => 0
188+
[1] => -1
189189
)
190190
Array
191191
(
@@ -233,7 +233,7 @@ Array
233233
)
234234
Array
235235
(
236-
[1] => 0
236+
[1] => -1
237237
)
238238
Array
239239
(
@@ -305,7 +305,7 @@ Array
305305
)
306306
Array
307307
(
308-
[1] => 0
308+
[1] => -1
309309
)
310310
Array
311311
(

0 commit comments

Comments
 (0)