X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_message_body.c;h=db86ab07ea8129e8c7a18d14ee306579f060c3a6;hp=79c8bf765095852bd2798cf1ae80e077a287de12;hb=19b4a9cd20fd1cdf5f896b21a2e7b0e3d177ebe3;hpb=d5d03014cff8c8ca80ee7866af100d3ceae1bd8f diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index 79c8bf7..db86ab0 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -214,7 +214,7 @@ size_t php_http_message_body_append(php_http_message_body_t *body, const char *b written = php_stream_write(s, buf, len); if (written != len) { - php_error_docref(NULL, E_WARNING, "Failed to append %zu bytes to body; wrote %zu", len, written); + php_error_docref(NULL, E_WARNING, "Failed to append %zu bytes to body; wrote %zu", len, written == (size_t) -1 ? 0 : written); } return len; @@ -330,7 +330,7 @@ static inline char *format_key(php_http_arrkey_t *key, const char *prefix) { } else if (key->key) { new_key = estrdup(key->key->val); } else { - new_key = estrdup(""); + spprintf(&new_key, 0, "%lu", key->h); } return new_key; @@ -392,14 +392,17 @@ static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const ZEND_HASH_FOREACH_KEY_VAL_IND(files, key.h, key.key, val) { if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) { - char *str = format_key(&key, name); + char *str = key.key ? format_key(&key, name) : NULL; + const char *prefix = str ?: name; - if (SUCCESS != add_recursive_files(body, str, HASH_OF(val))) { + if (SUCCESS != add_recursive_files(body, prefix, HASH_OF(val))) { efree(str); HT_UNPROTECT_RECURSION(files); return FAILURE; } - efree(str); + if (str) { + efree(str); + } } } ZEND_HASH_FOREACH_END();