From 87d1692e277362031f58fa5d2a653d6ea60de618 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 3 Jan 2017 21:35:49 +0100 Subject: [PATCH 1/3] nghttp2_submit: fix Parameter 'flags' is always rewritten in function body before being used found by PVS Studio (V763) --- lib/nghttp2_submit.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index cf9a7c0c..07656926 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -365,7 +365,7 @@ int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags _U_, return promised_stream_id; } -int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, +int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags _U_, int32_t stream_id, int32_t window_size_increment) { int rv; @@ -373,7 +373,6 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, if (window_size_increment == 0) { return 0; } - flags = 0; if (stream_id == 0) { rv = nghttp2_adjust_local_window_size( &session->local_window_size, &session->recv_window_size, @@ -404,14 +403,14 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, nghttp2_max(0, stream->consumed_size - window_size_increment); } - return nghttp2_session_add_window_update(session, flags, stream_id, + return nghttp2_session_add_window_update(session, 0, stream_id, window_size_increment); } return 0; } int nghttp2_session_set_local_window_size(nghttp2_session *session, - uint8_t flags, int32_t stream_id, + uint8_t flags _U_, int32_t stream_id, int32_t window_size) { int32_t window_size_increment; nghttp2_stream *stream; @@ -421,8 +420,6 @@ int nghttp2_session_set_local_window_size(nghttp2_session *session, return NGHTTP2_ERR_INVALID_ARGUMENT; } - flags = 0; - if (stream_id == 0) { window_size_increment = window_size - session->local_window_size; @@ -472,7 +469,7 @@ int nghttp2_session_set_local_window_size(nghttp2_session *session, } if (window_size_increment > 0) { - return nghttp2_session_add_window_update(session, flags, stream_id, + return nghttp2_session_add_window_update(session, 0, stream_id, window_size_increment); } From ae87a44b94aef53eb52edde7666439cbed67bd7d Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 3 Jan 2017 21:46:41 +0100 Subject: [PATCH 2/3] nghttp2_hd: fix It is odd that the body of 'hd_get_num_table_entries' function is fully equivalent to the body of 'get_max_index' function found by PVS Studio (V524) --- lib/nghttp2_hd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 6282b852..f1071623 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -2281,10 +2281,6 @@ ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, return decode_length(res, shift_ptr, fin, initial, shift, in, last, prefix); } -static size_t hd_get_num_table_entries(nghttp2_hd_context *context) { - return context->hd_table.len + NGHTTP2_STATIC_TABLE_LENGTH; -} - static const nghttp2_nv *hd_get_table_entry(nghttp2_hd_context *context, size_t idx) { if (idx == 0) { @@ -2301,7 +2297,7 @@ static const nghttp2_nv *hd_get_table_entry(nghttp2_hd_context *context, } size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater) { - return hd_get_num_table_entries(&deflater->ctx); + return get_max_index(&deflater->ctx); } const nghttp2_nv * @@ -2320,7 +2316,7 @@ nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater) { } size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater) { - return hd_get_num_table_entries(&inflater->ctx); + return get_max_index(&inflater->ctx); } const nghttp2_nv * From 8256c6e070b18f7e7fbb6a4d15e11a2fd74ec8a1 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 3 Jan 2017 21:54:28 +0100 Subject: [PATCH 3/3] libevent-client: fix Incorrect format found by PVS Studio (V576) Consider checking the fourth actual argument of the 'fprintf' function. The SIGNED integer type argument is expected. --- examples/libevent-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libevent-client.c b/examples/libevent-client.c index cd5811b5..8d0b7273 100644 --- a/examples/libevent-client.c +++ b/examples/libevent-client.c @@ -287,7 +287,7 @@ static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, int rv; if (session_data->stream_data->stream_id == stream_id) { - fprintf(stderr, "Stream %d closed with error_code=%d\n", stream_id, + fprintf(stderr, "Stream %d closed with error_code=%u\n", stream_id, error_code); rv = nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR); if (rv != 0) {