mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
zlib: use zend_string_{extend,truncate} over *_realloc (#18462)
These cases seemed obvious enough to me to confidently change as an outsider to zlib.
This commit is contained in:
parent
39a56a1687
commit
6406d5f792
1 changed files with 4 additions and 4 deletions
|
@ -991,7 +991,7 @@ PHP_FUNCTION(inflate_add)
|
|||
case Z_OK:
|
||||
if (ctx->Z.avail_out == 0) {
|
||||
/* more output buffer space needed; realloc and try again */
|
||||
out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
|
||||
out = zend_string_extend(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
|
||||
ctx->Z.avail_out = CHUNK_SIZE;
|
||||
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
|
||||
break;
|
||||
|
@ -1003,7 +1003,7 @@ PHP_FUNCTION(inflate_add)
|
|||
case Z_BUF_ERROR:
|
||||
if (flush_type == Z_FINISH && ctx->Z.avail_out == 0) {
|
||||
/* more output buffer space needed; realloc and try again */
|
||||
out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
|
||||
out = zend_string_extend(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
|
||||
ctx->Z.avail_out = CHUNK_SIZE;
|
||||
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
|
||||
break;
|
||||
|
@ -1039,7 +1039,7 @@ PHP_FUNCTION(inflate_add)
|
|||
} while (1);
|
||||
|
||||
complete:
|
||||
out = zend_string_realloc(out, buffer_used, 0);
|
||||
out = zend_string_truncate(out, buffer_used, 0);
|
||||
ZSTR_VAL(out)[buffer_used] = 0;
|
||||
RETURN_STR(out);
|
||||
}
|
||||
|
@ -1228,7 +1228,7 @@ PHP_FUNCTION(deflate_add)
|
|||
if (ctx->Z.avail_out == 0) {
|
||||
/* more output buffer space needed; realloc and try again */
|
||||
/* adding 64 more bytes solved every issue I have seen */
|
||||
out = zend_string_realloc(out, ZSTR_LEN(out) + 64, 0);
|
||||
out = zend_string_extend(out, ZSTR_LEN(out) + 64, 0);
|
||||
ctx->Z.avail_out = 64;
|
||||
ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue