coverity fixes
authorMichael Wallner <mike@php.net>
Wed, 14 Sep 2016 07:39:59 +0000 (09:39 +0200)
committerMichael Wallner <mike@php.net>
Wed, 14 Sep 2016 07:39:59 +0000 (09:39 +0200)
src/php_http_buffer.c
src/php_http_encoding.c
src/php_http_env_response.c
src/php_http_etag.c
src/php_http_filter.c
src/php_http_message.c

index eaebfa0..64e559a 100644 (file)
@@ -32,9 +32,13 @@ PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t
 
 PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_buffer_t *buf, const char *string, size_t length)
 {
+       int free_buf = !!buf;
+
        if ((buf = php_http_buffer_init(buf))) {
                if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, string, length)) {
-                       pefree(buf, buf->pmem);
+                       if (free_buf) {
+                               pefree(buf, buf->pmem);
+                       }
                        buf = NULL;
                }
        }
index 286f2b5..6d32652 100644 (file)
@@ -222,7 +222,7 @@ retry_raw_inflate:
                }
                inflateEnd(&Z);
 
-               if (decoded_len && *decoded) {
+               if (*decoded_len && *decoded) {
                        efree(*decoded);
                }
        }
index 20a31eb..b4927a1 100644 (file)
@@ -369,10 +369,6 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                zval_ptr_dtor(&zoption);
        }
 
-       if (ret != SUCCESS) {
-               return ret;
-       }
-
        if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
                zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
 
index 4e5fd69..4d34d57 100644 (file)
@@ -80,7 +80,7 @@ char *php_http_etag_finish(php_http_etag_t *e)
 #ifdef PHP_HTTP_HAVE_HASH
                const php_hash_ops *eho = NULL;
 
-               if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
+               if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
                        eho->hash_final(digest, e->ctx);
                        etag = php_http_etag_digest(digest, eho->digest_size);
                }
@@ -110,7 +110,7 @@ size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t dat
 #ifdef PHP_HTTP_HAVE_HASH
                const php_hash_ops *eho = NULL;
 
-               if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
+               if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
                        eho->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len);
                }
 #endif
index b6d967b..9b39104 100644 (file)
@@ -302,7 +302,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                
                nxt = ptr->next;
                php_stream_bucket_unlink(ptr TSRMLS_CC);
-               php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "update: deflate (-> %zu) (w: %zu, r: %zu)\n", encoded_len, stream->writepos, stream->readpos);
@@ -322,7 +324,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                char *encoded = NULL;
                size_t encoded_len = 0;
                
-               php_http_encoding_stream_flush(buffer, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_flush(buffer, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "flush: deflate (-> %zu)\n", encoded_len);
@@ -340,7 +344,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                char *encoded = NULL;
                size_t encoded_len = 0;
                
-               php_http_encoding_stream_finish(buffer, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_finish(buffer, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "finish: deflate (-> %zu)\n", encoded_len);
index 60569b8..3186b79 100644 (file)
@@ -436,7 +436,7 @@ php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
        if (c > 1) {
                php_http_message_t *tmp = msg, **arr;
 
-               arr = ecalloc(c, sizeof(**arr));
+               arr = ecalloc(c, sizeof(*arr));
                for (i = 0; i < c; ++i) {
                        arr[i] = tmp;
                        tmp = tmp->parent;
@@ -702,7 +702,7 @@ void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_D
                php_http_message_object_t **objects;
                int last;
 
-               objects = ecalloc(i, sizeof(**objects));
+               objects = ecalloc(i, sizeof(*objects));
 
                /* we are the first message */
                objects[0] = obj;