} else {
size_t bits_per_word = size * 8;
size_t count = (mpz_sizeinbase(gmpnumber, 2) + bits_per_word - 1) / bits_per_word;
- size_t out_len = count * size;
- zend_string *out_string = zend_string_alloc(out_len, 0);
+ zend_string *out_string = zend_string_safe_alloc(count, out_len, 0, 0);
mpz_export(ZSTR_VAL(out_string), NULL, order, size, endian, 0, gmpnumber);
- ZSTR_VAL(out_string)[out_len] = '\0';
+ ZSTR_VAL(out_string)[ZSTR_LEN(out_string)] = '\0';
RETURN_NEW_STR(out_string);
}
return;
}
- result = zend_string_safe_alloc(ZSTR_LEN(input), 1, num_pad_chars, 0);
+ result = zend_string_safe_alloc(1, ZSTR_LEN(input), num_pad_chars, 0);
ZSTR_LEN(result) = 0;
/* We need to figure out the left/right padding lengths. */
static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t maxlen)
{
size_t i, j;
- zend_string *str = zend_string_alloc(len, 0);
+ zend_string *str = zend_string_safe_alloc(1, len, 0, 0);
unsigned char *end = *(unsigned char **)p+maxlen;
if (end < *p) {
static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t maxlen)
{
size_t i, j;
- zend_string *str = zend_string_alloc(len, 0);
+ zend_string *str = zend_string_safe_alloc(1, len, 0, 0);
unsigned char *end = *(unsigned char **)p+maxlen;
if (end < *p) {