Skip to content

Commit 7c87988

Browse files
committed
Small cleanup in pack() implementation
1 parent 6886bb6 commit 7c87988

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

ext/standard/pack.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,21 @@ PHP_FUNCTION(pack)
115115
int num_args, i;
116116
int currentarg;
117117
char *format;
118-
int formatlen;
118+
size_t formatlen;
119119
char *formatcodes;
120120
int *formatargs;
121121
int formatcount = 0;
122122
int outputpos = 0, outputsize = 0;
123123
zend_string *output;
124124

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) {
126126
return;
127127
}
128128

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-
137129
/* We have a maximum of <formatlen> format codes to deal with */
138130
formatcodes = safe_emalloc(formatlen, sizeof(*formatcodes), 0);
139131
formatargs = safe_emalloc(formatlen, sizeof(*formatargs), 0);
140-
currentarg = 1;
132+
currentarg = 0;
141133

142134
/* Preprocess format into formatcodes and formatargs */
143135
for (i = 0; i < formatlen; formatcount++) {
@@ -187,10 +179,7 @@ PHP_FUNCTION(pack)
187179
}
188180

189181
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]);
194183
arg = Z_STRLEN(argv[currentarg]);
195184
if (code == 'Z') {
196185
/* add one because Z is always NUL-terminated:
@@ -334,7 +323,7 @@ PHP_FUNCTION(pack)
334323

335324
output = zend_string_alloc(outputsize, 0);
336325
outputpos = 0;
337-
currentarg = 1;
326+
currentarg = 0;
338327

339328
/* Do actual packing */
340329
for (i = 0; i < formatcount; i++) {

0 commit comments

Comments
 (0)