summaryrefslogtreecommitdiffstats
path: root/php-wip2.patch
blob: 91535e941fcf7f8fb001d1635c31da401d019145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From 4d8d5d83fce83c32a04cd8d8cf50d909ab101f38 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 11 Dec 2012 16:30:08 +0100
Subject: [PATCH] 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"
---
 ext/standard/pack.c                    |  3 +--
 ext/standard/tests/strings/pack_Z.phpt | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

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"
+}
-- 
1.7.11.5