Skip to content

Commit 6406d5f

Browse files
authored
zlib: use zend_string_{extend,truncate} over *_realloc (php#18462)
These cases seemed obvious enough to me to confidently change as an outsider to zlib.
1 parent 39a56a1 commit 6406d5f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/zlib/zlib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ PHP_FUNCTION(inflate_add)
991991
case Z_OK:
992992
if (ctx->Z.avail_out == 0) {
993993
/* more output buffer space needed; realloc and try again */
994-
out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
994+
out = zend_string_extend(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
995995
ctx->Z.avail_out = CHUNK_SIZE;
996996
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
997997
break;
@@ -1003,7 +1003,7 @@ PHP_FUNCTION(inflate_add)
10031003
case Z_BUF_ERROR:
10041004
if (flush_type == Z_FINISH && ctx->Z.avail_out == 0) {
10051005
/* more output buffer space needed; realloc and try again */
1006-
out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
1006+
out = zend_string_extend(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
10071007
ctx->Z.avail_out = CHUNK_SIZE;
10081008
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
10091009
break;
@@ -1039,7 +1039,7 @@ PHP_FUNCTION(inflate_add)
10391039
} while (1);
10401040

10411041
complete:
1042-
out = zend_string_realloc(out, buffer_used, 0);
1042+
out = zend_string_truncate(out, buffer_used, 0);
10431043
ZSTR_VAL(out)[buffer_used] = 0;
10441044
RETURN_STR(out);
10451045
}
@@ -1228,7 +1228,7 @@ PHP_FUNCTION(deflate_add)
12281228
if (ctx->Z.avail_out == 0) {
12291229
/* more output buffer space needed; realloc and try again */
12301230
/* adding 64 more bytes solved every issue I have seen */
1231-
out = zend_string_realloc(out, ZSTR_LEN(out) + 64, 0);
1231+
out = zend_string_extend(out, ZSTR_LEN(out) + 64, 0);
12321232
ctx->Z.avail_out = 64;
12331233
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
12341234
}

0 commit comments

Comments
 (0)