From b2be5b163e896bb9cbb3f28314551d0debf8408d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 14 Sep 2016 09:39:24 +0200 Subject: [PATCH 1/1] coverity fixes --- src/php_http_client_curl.c | 17 +++++++++-------- src/php_http_url.c | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c index cca6a27..71afd6f 100644 --- a/src/php_http_client_curl.c +++ b/src/php_http_client_curl.c @@ -923,20 +923,23 @@ static ZEND_RESULT_CODE php_http_curle_option_set_range(php_http_option_t *opt, if (val && Z_TYPE_P(val) != IS_NULL) { zval *rr, *rb, *re; - zend_long rbl, rel; HashTable *ht = HASH_OF(val); ZEND_HASH_FOREACH_VAL(ht, rr) { if (Z_TYPE_P(rr) == IS_ARRAY) { if (2 == php_http_array_list(Z_ARRVAL_P(rr), 2, &rb, &re)) { - if ( ((Z_TYPE_P(rb) == IS_LONG) || ((Z_TYPE_P(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_P(rb), Z_STRLEN_P(rb), &rbl, NULL, 1))) && - ((Z_TYPE_P(re) == IS_LONG) || ((Z_TYPE_P(re) == IS_STRING) && is_numeric_string(Z_STRVAL_P(re), Z_STRLEN_P(re), &rel, NULL, 1)))) { - if ((rbl >= 0) && (rel >= 0)) { + zend_long rbl = zval_get_long(rb), rel = zval_get_long(re); + + if (rbl >= 0) { + if (rel > 0) { php_http_buffer_appendf(&curl->options.ranges, "%ld-%ld,", rbl, rel); + } else { + php_http_buffer_appendf(&curl->options.ranges, "%ld-", rbl); } + } else if (rel > 0) { + php_http_buffer_appendf(&curl->options.ranges, "-%ld", rel); } - } } } @@ -1751,15 +1754,13 @@ static ZEND_RESULT_CODE php_http_curlm_set_option(php_http_option_t *opt, zval * php_http_client_t *client = userdata; php_http_client_curl_t *curl = client->ctx; CURLM *ch = curl->handle->multi; - zval *orig = val; + zval zopt, *orig = val; CURLMcode rc = CURLM_UNKNOWN_OPTION; ZEND_RESULT_CODE rv = SUCCESS; if (!val) { val = &opt->defval; } else if (opt->type && Z_TYPE_P(val) != opt->type && !(Z_TYPE_P(val) == IS_NULL && opt->type == IS_ARRAY)) { - zval zopt; - ZVAL_DUP(&zopt, val); convert_to_explicit_type(&zopt, opt->type); diff --git a/src/php_http_url.c b/src/php_http_url.c index b828c46..2332fb5 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -503,7 +503,7 @@ php_http_url_t *php_http_url_from_struct(HashTable *ht) HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct) { - HashTable *ht; + HashTable *ht = NULL; zval tmp; if (strct) { @@ -523,8 +523,8 @@ HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct) } #define url_struct_add(part) \ - if (Z_TYPE_P(strct) == IS_ARRAY) { \ - zend_hash_str_update(Z_ARRVAL_P(strct), part, lenof(part), &tmp); \ + if (!strct || Z_TYPE_P(strct) == IS_ARRAY) { \ + zend_hash_str_update(ht, part, lenof(part), &tmp); \ } else { \ zend_update_property(Z_OBJCE_P(strct), strct, part, lenof(part), &tmp); \ zval_ptr_dtor(&tmp); \ -- 2.30.2