Skip to content

Commit dc098b0

Browse files
committed
Avoiding str duplication
1 parent 42b3bf9 commit dc098b0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ext/standard/pack.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ PHP_FUNCTION(unpack)
969969
zend_long len = (inputlen - inputpos) * 2; /* Remaining */
970970
int nibbleshift = (type == 'h') ? 0 : 4;
971971
int first = 1;
972-
char *buf;
972+
zend_string *buf;
973973
zend_long ipos, opos;
974974

975975
/* If size was given take minimum of len and size */
@@ -981,7 +981,7 @@ PHP_FUNCTION(unpack)
981981
len -= argb % 2;
982982
}
983983

984-
buf = emalloc(len + 1);
984+
buf = zend_string_alloc(len, 0);
985985

986986
for (ipos = opos = 0; opos < len; opos++) {
987987
char cc = (input[inputpos + ipos] >> nibbleshift) & 0xf;
@@ -992,7 +992,7 @@ PHP_FUNCTION(unpack)
992992
cc += 'a' - 10;
993993
}
994994

995-
buf[opos] = cc;
995+
ZSTR_VAL(buf)[opos] = cc;
996996
nibbleshift = (nibbleshift + 4) & 7;
997997

998998
if (first-- == 0) {
@@ -1001,9 +1001,8 @@ PHP_FUNCTION(unpack)
10011001
}
10021002
}
10031003

1004-
buf[len] = '\0';
1005-
add_assoc_stringl(return_value, n, buf, len);
1006-
efree(buf);
1004+
ZSTR_VAL(buf)[len] = '\0';
1005+
add_assoc_str(return_value, n, buf);
10071006
break;
10081007
}
10091008

0 commit comments

Comments
 (0)