@@ -115,29 +115,21 @@ PHP_FUNCTION(pack)
115
115
int num_args , i ;
116
116
int currentarg ;
117
117
char * format ;
118
- int formatlen ;
118
+ size_t formatlen ;
119
119
char * formatcodes ;
120
120
int * formatargs ;
121
121
int formatcount = 0 ;
122
122
int outputpos = 0 , outputsize = 0 ;
123
123
zend_string * output ;
124
124
125
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "+" , & argv , & num_args ) == FAILURE ) {
125
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "s+" , & format , & formatlen , & argv , & num_args ) == FAILURE ) {
126
126
return ;
127
127
}
128
128
129
- if (Z_ISREF (argv [0 ])) {
130
- SEPARATE_ZVAL (& argv [0 ]);
131
- }
132
- convert_to_string_ex (& argv [0 ]);
133
-
134
- format = Z_STRVAL (argv [0 ]);
135
- formatlen = Z_STRLEN (argv [0 ]);
136
-
137
129
/* We have a maximum of <formatlen> format codes to deal with */
138
130
formatcodes = safe_emalloc (formatlen , sizeof (* formatcodes ), 0 );
139
131
formatargs = safe_emalloc (formatlen , sizeof (* formatargs ), 0 );
140
- currentarg = 1 ;
132
+ currentarg = 0 ;
141
133
142
134
/* Preprocess format into formatcodes and formatargs */
143
135
for (i = 0 ; i < formatlen ; formatcount ++ ) {
@@ -187,10 +179,7 @@ PHP_FUNCTION(pack)
187
179
}
188
180
189
181
if (arg < 0 ) {
190
- if (Z_ISREF (argv [currentarg ])) {
191
- SEPARATE_ZVAL (& argv [currentarg ]);
192
- }
193
- convert_to_string_ex (& argv [currentarg ]);
182
+ convert_to_string (& argv [currentarg ]);
194
183
arg = Z_STRLEN (argv [currentarg ]);
195
184
if (code == 'Z' ) {
196
185
/* add one because Z is always NUL-terminated:
@@ -334,7 +323,7 @@ PHP_FUNCTION(pack)
334
323
335
324
output = zend_string_alloc (outputsize , 0 );
336
325
outputpos = 0 ;
337
- currentarg = 1 ;
326
+ currentarg = 0 ;
338
327
339
328
/* Do actual packing */
340
329
for (i = 0 ; i < formatcount ; i ++ ) {
0 commit comments