projects
/
m6w6
/
ext-http
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
fix usage of hash_init() in 8.1
[m6w6/ext-http]
/
src
/
php_http_buffer.c
diff --git
a/src/php_http_buffer.c
b/src/php_http_buffer.c
index b84bcd0cb37ac247d06b5e7b7591435c02798a67..5913cfcd60bd0633fe603ad651ff25c8875ce521 100644
(file)
--- a/
src/php_http_buffer.c
+++ b/
src/php_http_buffer.c
@@
-10,7
+10,7
@@
+--------------------------------------------------------------------+
*/
+--------------------------------------------------------------------+
*/
-#include
<php.h>
+#include
"php_http_api.h"
#include "php_http_buffer.h"
PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(
#include "php_http_buffer.h"
PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(
@@
-35,9
+35,13
@@
PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(
PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(
php_http_buffer_t *buf, const char *str, size_t len)
{
PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(
php_http_buffer_t *buf, const char *str, size_t len)
{
- if ((buf = php_http_buffer_init(buf))) {
+ int free_buf = !!buf;
+
+ if (EXPECTED(buf = php_http_buffer_init(buf))) {
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, str, len)) {
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, str, len)) {
- pefree(buf, buf->pmem);
+ if (free_buf) {
+ pefree(buf, buf->pmem);
+ }
buf = NULL;
}
}
buf = NULL;
}
}
@@
-55,7
+59,7
@@
PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(
if (buf->free < len) {
size_t size = override_size ? override_size : buf->size;
if (buf->free < len) {
size_t size = override_size ? override_size : buf->size;
- while (
(size + buf->free) < len
) {
+ while (
UNEXPECTED((size + buf->free) < len)
) {
size <<= 1;
}
size <<= 1;
}
@@
-113,9
+117,11
@@
PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf,
) {
return PHP_HTTP_BUFFER_NOMEM;
}
) {
return PHP_HTTP_BUFFER_NOMEM;
}
- memcpy(buf->data + buf->used, append, append_len);
- buf->used += append_len;
- buf->free -= append_len;
+ if (append_len) {
+ memcpy(buf->data + buf->used, append, append_len);
+ buf->used += append_len;
+ buf->free -= append_len;
+ }
return append_len;
}
return append_len;
}
@@
-143,7
+149,9
@@
PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf,
char **into, size_t *len)
{
char *copy = ecalloc(1, buf->used + 1);
char **into, size_t *len)
{
char *copy = ecalloc(1, buf->used + 1);
- memcpy(copy, buf->data, buf->used);
+ if (buf->data) {
+ memcpy(copy, buf->data, buf->used);
+ }
if (into) {
*into = copy;
}
if (into) {
*into = copy;
}
@@
-296,7
+304,7
@@
PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s,
php_http_buffer_t *str;
size_t passed;
php_http_buffer_t *str;
size_t passed;
- if (
!*s
) {
+ if (
UNEXPECTED(!*s)
) {
*s = php_http_buffer_init_ex(NULL, chunk_size,
chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
}
*s = php_http_buffer_init_ex(NULL, chunk_size,
chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
}