From 7c8798834aefe4d4071eb66020e7dfa47111e343 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 9 Sep 2015 03:58:37 +0200 Subject: [PATCH] Small cleanup in pack() implementation --- ext/standard/pack.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/ext/standard/pack.c b/ext/standard/pack.c index f46f8967e9f..8b4103850e8 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -115,29 +115,21 @@ PHP_FUNCTION(pack) int num_args, i; int currentarg; char *format; - int formatlen; + size_t formatlen; char *formatcodes; int *formatargs; int formatcount = 0; int outputpos = 0, outputsize = 0; zend_string *output; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &argv, &num_args) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s+", &format, &formatlen, &argv, &num_args) == FAILURE) { return; } - if (Z_ISREF(argv[0])) { - SEPARATE_ZVAL(&argv[0]); - } - convert_to_string_ex(&argv[0]); - - format = Z_STRVAL(argv[0]); - formatlen = Z_STRLEN(argv[0]); - /* We have a maximum of format codes to deal with */ formatcodes = safe_emalloc(formatlen, sizeof(*formatcodes), 0); formatargs = safe_emalloc(formatlen, sizeof(*formatargs), 0); - currentarg = 1; + currentarg = 0; /* Preprocess format into formatcodes and formatargs */ for (i = 0; i < formatlen; formatcount++) { @@ -187,10 +179,7 @@ PHP_FUNCTION(pack) } if (arg < 0) { - if (Z_ISREF(argv[currentarg])) { - SEPARATE_ZVAL(&argv[currentarg]); - } - convert_to_string_ex(&argv[currentarg]); + convert_to_string(&argv[currentarg]); arg = Z_STRLEN(argv[currentarg]); if (code == 'Z') { /* add one because Z is always NUL-terminated: @@ -334,7 +323,7 @@ PHP_FUNCTION(pack) output = zend_string_alloc(outputsize, 0); outputpos = 0; - currentarg = 1; + currentarg = 0; /* Do actual packing */ for (i = 0; i < formatcount; i++) {