diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-11 16:46:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-11 16:46:30 +0000 |
commit | 8e1187a02b785e56d798660a9a292ca385e1f6aa (patch) | |
tree | b035593aa2ae37c25aeb28b537a3223c52532ab1 /lib | |
parent | Adding upstream version 1.61.0. (diff) | |
download | nghttp2-8e1187a02b785e56d798660a9a292ca385e1f6aa.tar.xz nghttp2-8e1187a02b785e56d798660a9a292ca385e1f6aa.zip |
Adding upstream version 1.62.1.upstream/1.62.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/nghttp2_buf.c | 4 | ||||
-rw-r--r-- | lib/nghttp2_hd.c | 12 | ||||
-rw-r--r-- | lib/nghttp2_hd_huffman.c | 4 | ||||
-rw-r--r-- | lib/nghttp2_helper.c | 6 | ||||
-rw-r--r-- | lib/nghttp2_helper.h | 27 | ||||
-rw-r--r-- | lib/nghttp2_pq.c | 2 | ||||
-rw-r--r-- | lib/nghttp2_ratelim.c | 2 | ||||
-rw-r--r-- | lib/nghttp2_session.c | 47 | ||||
-rw-r--r-- | lib/nghttp2_stream.c | 2 | ||||
-rw-r--r-- | lib/nghttp2_submit.c | 4 |
10 files changed, 70 insertions, 40 deletions
diff --git a/lib/nghttp2_buf.c b/lib/nghttp2_buf.c index 101035f..15cd674 100644 --- a/lib/nghttp2_buf.c +++ b/lib/nghttp2_buf.c @@ -61,7 +61,7 @@ int nghttp2_buf_reserve(nghttp2_buf *buf, size_t new_cap, nghttp2_mem *mem) { return 0; } - new_cap = nghttp2_max(new_cap, cap * 2); + new_cap = nghttp2_max_size(new_cap, cap * 2); ptr = nghttp2_mem_realloc(mem, buf->begin, new_cap); if (ptr == NULL) { @@ -343,7 +343,7 @@ int nghttp2_bufs_add(nghttp2_bufs *bufs, const void *data, size_t len) { while (len) { buf = &bufs->cur->buf; - nwrite = nghttp2_min(nghttp2_buf_avail(buf), len); + nwrite = nghttp2_min_size(nghttp2_buf_avail(buf), len); if (nwrite == 0) { rv = bufs_alloc_chain(bufs); if (rv != 0) { diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 1b0c713..cab6ec8 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -1245,13 +1245,13 @@ static void hd_context_shrink_table_size(nghttp2_hd_context *context, int nghttp2_hd_deflate_change_table_size( nghttp2_hd_deflater *deflater, size_t settings_max_dynamic_table_size) { - size_t next_bufsize = nghttp2_min(settings_max_dynamic_table_size, - deflater->deflate_hd_table_bufsize_max); + size_t next_bufsize = nghttp2_min_size( + settings_max_dynamic_table_size, deflater->deflate_hd_table_bufsize_max); deflater->ctx.hd_table_bufsize_max = next_bufsize; deflater->min_hd_table_bufsize_max = - nghttp2_min(deflater->min_hd_table_bufsize_max, next_bufsize); + nghttp2_min_size(deflater->min_hd_table_bufsize_max, next_bufsize); deflater->notify_table_size_change = 1; @@ -1738,7 +1738,7 @@ static nghttp2_ssize hd_inflate_read_huff(nghttp2_hd_inflater *inflater, static nghttp2_ssize hd_inflate_read(nghttp2_hd_inflater *inflater, nghttp2_buf *buf, const uint8_t *in, const uint8_t *last) { - size_t len = nghttp2_min((size_t)(last - in), inflater->left); + size_t len = nghttp2_min_size((size_t)(last - in), inflater->left); buf->last = nghttp2_cpymem(buf->last, in, len); @@ -1962,8 +1962,8 @@ nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, rfin = 0; rv = hd_inflate_read_len( inflater, &rfin, in, last, 5, - nghttp2_min(inflater->min_hd_table_bufsize_max, - inflater->settings_hd_table_bufsize_max)); + nghttp2_min_size(inflater->min_hd_table_bufsize_max, + inflater->settings_hd_table_bufsize_max)); if (rv < 0) { goto fail; } diff --git a/lib/nghttp2_hd_huffman.c b/lib/nghttp2_hd_huffman.c index 959053f..f848f36 100644 --- a/lib/nghttp2_hd_huffman.c +++ b/lib/nghttp2_hd_huffman.c @@ -116,7 +116,9 @@ nghttp2_ssize nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, uint8_t c; /* We use the decoding algorithm described in - http://graphics.ics.uci.edu/pub/Prefix.pdf */ + - http://graphics.ics.uci.edu/pub/Prefix.pdf [!!! NO LONGER VALID !!!] + - https://ics.uci.edu/~dan/pubs/Prefix.pdf + - https://github.com/nghttp2/nghttp2/files/15141264/Prefix.pdf */ for (; src != end;) { c = *src++; t = &huff_decode_table[t->fstate & 0x1ff][c >> 4]; diff --git a/lib/nghttp2_helper.c b/lib/nghttp2_helper.c index b3563d9..9a2407a 100644 --- a/lib/nghttp2_helper.c +++ b/lib/nghttp2_helper.c @@ -160,7 +160,7 @@ int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr, int32_t recv_reduction_delta; int32_t delta; int32_t new_recv_window_size = - nghttp2_max(0, *recv_window_size_ptr) - *delta_ptr; + nghttp2_max_int32(0, *recv_window_size_ptr) - *delta_ptr; if (new_recv_window_size >= 0) { *recv_window_size_ptr = new_recv_window_size; @@ -177,7 +177,7 @@ int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr, *local_window_size_ptr += delta; /* If there is recv_reduction due to earlier window_size reduction, we have to adjust it too. */ - recv_reduction_delta = nghttp2_min(*recv_reduction_ptr, delta); + recv_reduction_delta = nghttp2_min_int32(*recv_reduction_ptr, delta); *recv_reduction_ptr -= recv_reduction_delta; if (*recv_window_size_ptr < 0) { *recv_window_size_ptr += recv_reduction_delta; @@ -233,7 +233,7 @@ int nghttp2_increase_local_window_size(int32_t *local_window_size_ptr, *local_window_size_ptr += delta; /* If there is recv_reduction due to earlier window_size reduction, we have to adjust it too. */ - recv_reduction_delta = nghttp2_min(*recv_reduction_ptr, delta); + recv_reduction_delta = nghttp2_min_int32(*recv_reduction_ptr, delta); *recv_reduction_ptr -= recv_reduction_delta; *recv_window_size_ptr += recv_reduction_delta; diff --git a/lib/nghttp2_helper.h b/lib/nghttp2_helper.h index b1f18ce..01b85c4 100644 --- a/lib/nghttp2_helper.h +++ b/lib/nghttp2_helper.h @@ -35,8 +35,31 @@ #include <nghttp2/nghttp2.h> #include "nghttp2_mem.h" -#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B)) -#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B)) +#define nghttp2_max_def(SUFFIX, T) \ + static inline T nghttp2_max_##SUFFIX(T a, T b) { return a < b ? b : a; } + +nghttp2_max_def(int8, int8_t); +nghttp2_max_def(int16, int16_t); +nghttp2_max_def(int32, int32_t); +nghttp2_max_def(int64, int64_t); +nghttp2_max_def(uint8, uint8_t); +nghttp2_max_def(uint16, uint16_t); +nghttp2_max_def(uint32, uint32_t); +nghttp2_max_def(uint64, uint64_t); +nghttp2_max_def(size, size_t); + +#define nghttp2_min_def(SUFFIX, T) \ + static inline T nghttp2_min_##SUFFIX(T a, T b) { return a < b ? a : b; } + +nghttp2_min_def(int8, int8_t); +nghttp2_min_def(int16, int16_t); +nghttp2_min_def(int32, int32_t); +nghttp2_min_def(int64, int64_t); +nghttp2_min_def(uint8, uint8_t); +nghttp2_min_def(uint16, uint16_t); +nghttp2_min_def(uint32, uint32_t); +nghttp2_min_def(uint64, uint64_t); +nghttp2_min_def(size, size_t); #define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0) diff --git a/lib/nghttp2_pq.c b/lib/nghttp2_pq.c index 64353ac..e79ba83 100644 --- a/lib/nghttp2_pq.c +++ b/lib/nghttp2_pq.c @@ -69,7 +69,7 @@ int nghttp2_pq_push(nghttp2_pq *pq, nghttp2_pq_entry *item) { void *nq; size_t ncapacity; - ncapacity = nghttp2_max(4, (pq->capacity * 2)); + ncapacity = nghttp2_max_size(4, (pq->capacity * 2)); nq = nghttp2_mem_realloc(pq->mem, pq->q, ncapacity * sizeof(nghttp2_pq_entry *)); diff --git a/lib/nghttp2_ratelim.c b/lib/nghttp2_ratelim.c index 7011655..604ac08 100644 --- a/lib/nghttp2_ratelim.c +++ b/lib/nghttp2_ratelim.c @@ -61,7 +61,7 @@ void nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp) { } rl->val += gain; - rl->val = nghttp2_min(rl->val, rl->burst); + rl->val = nghttp2_min_uint64(rl->val, rl->burst); } int nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n) { diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 004a4df..54746fb 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1700,10 +1700,11 @@ int nghttp2_session_adjust_idle_stream(nghttp2_session *session) { /* Make minimum number of idle streams 16, and maximum 100, which are arbitrary chosen numbers. */ - max = nghttp2_min( - 100, nghttp2_max( - 16, nghttp2_min(session->local_settings.max_concurrent_streams, - session->pending_local_max_concurrent_stream))); + max = nghttp2_min_uint32( + 100, nghttp2_max_uint32( + 16, nghttp2_min_uint32( + session->local_settings.max_concurrent_streams, + session->pending_local_max_concurrent_stream))); DEBUGF("stream: adjusting kept idle streams num_idle_streams=%zu, max=%zu\n", session->num_idle_streams, max); @@ -2131,10 +2132,11 @@ static nghttp2_ssize nghttp2_session_enforce_flow_control_limits( session->remote_window_size, session->remote_settings.max_frame_size, stream->stream_id, stream->remote_window_size); - return nghttp2_min(nghttp2_min(nghttp2_min(requested_window_size, - stream->remote_window_size), - session->remote_window_size), - (int32_t)session->remote_settings.max_frame_size); + return nghttp2_min_int32( + nghttp2_min_int32(nghttp2_min_int32((int32_t)requested_window_size, + stream->remote_window_size), + session->remote_window_size), + (int32_t)session->remote_settings.max_frame_size); } /* @@ -2218,7 +2220,7 @@ static nghttp2_ssize session_call_select_padding(nghttp2_session *session, } max_paddedlen = - nghttp2_min(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); + nghttp2_min_size(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); if (session->callbacks.select_padding_callback2) { rv = session->callbacks.select_padding_callback2( @@ -2248,8 +2250,8 @@ static int session_headers_add_pad(nghttp2_session *session, aob = &session->aob; framebufs = &aob->framebufs; - max_payloadlen = nghttp2_min(NGHTTP2_MAX_PAYLOADLEN, - frame->hd.length + NGHTTP2_MAX_PADLEN); + max_payloadlen = nghttp2_min_size(NGHTTP2_MAX_PAYLOADLEN, + frame->hd.length + NGHTTP2_MAX_PADLEN); padded_payloadlen = session_call_select_padding(session, frame, max_payloadlen); @@ -2289,7 +2291,7 @@ static int session_pack_extension(nghttp2_session *session, nghttp2_bufs *bufs, session->callbacks.pack_extension_callback); buf = &bufs->head->buf; - buflen = nghttp2_min(nghttp2_buf_avail(buf), NGHTTP2_MAX_PAYLOADLEN); + buflen = nghttp2_min_size(nghttp2_buf_avail(buf), NGHTTP2_MAX_PAYLOADLEN); if (session->callbacks.pack_extension_callback2) { rv = session->callbacks.pack_extension_callback2(session, buf->last, buflen, @@ -4708,7 +4710,8 @@ int nghttp2_session_update_local_settings(nghttp2_session *session, case NGHTTP2_SETTINGS_HEADER_TABLE_SIZE: header_table_size_seen = 1; header_table_size = iv[i].value; - min_header_table_size = nghttp2_min(min_header_table_size, iv[i].value); + min_header_table_size = + nghttp2_min_uint32(min_header_table_size, iv[i].value); break; case NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE: new_initial_window_size = (int32_t)iv[i].value; @@ -5594,7 +5597,7 @@ static int session_update_consumed_size(nghttp2_session *session, /* recv_window_size may be smaller than consumed_size, because it may be decreased by negative value with nghttp2_submit_window_update(). */ - recv_size = nghttp2_min(*consumed_size_ptr, *recv_window_size_ptr); + recv_size = nghttp2_min_int32(*consumed_size_ptr, *recv_window_size_ptr); if (nghttp2_should_send_window_update(local_window_size, recv_size)) { rv = nghttp2_session_add_window_update(session, NGHTTP2_FLAG_NONE, @@ -5717,7 +5720,7 @@ fail: static size_t inbound_frame_payload_readlen(nghttp2_inbound_frame *iframe, const uint8_t *in, const uint8_t *last) { - return nghttp2_min((size_t)(last - in), iframe->payloadleft); + return nghttp2_min_size((size_t)(last - in), iframe->payloadleft); } /* @@ -5732,8 +5735,8 @@ static size_t inbound_frame_buf_read(nghttp2_inbound_frame *iframe, const uint8_t *in, const uint8_t *last) { size_t readlen; - readlen = - nghttp2_min((size_t)(last - in), nghttp2_buf_mark_avail(&iframe->sbuf)); + readlen = nghttp2_min_size((size_t)(last - in), + nghttp2_buf_mark_avail(&iframe->sbuf)); iframe->sbuf.last = nghttp2_cpymem(iframe->sbuf.last, in, readlen); @@ -5900,7 +5903,7 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, for (;;) { switch (iframe->state) { case NGHTTP2_IB_READ_CLIENT_MAGIC: - readlen = nghttp2_min(inlen, iframe->payloadleft); + readlen = nghttp2_min_size(inlen, iframe->payloadleft); if (memcmp(&NGHTTP2_CLIENT_MAGIC[NGHTTP2_CLIENT_MAGIC_LEN - iframe->payloadleft], @@ -7509,7 +7512,8 @@ int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_stream_id, /* last_stream_id must not be increased from the value previously sent */ - last_stream_id = nghttp2_min(last_stream_id, session->local_last_stream_id); + last_stream_id = + nghttp2_min_int32(last_stream_id, session->local_last_stream_id); nghttp2_frame_goaway_init(&frame->goaway, last_stream_id, error_code, opaque_data_copy, opaque_data_len); @@ -7823,7 +7827,8 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, frame->hd.length = (size_t)payloadlen; frame->data.padlen = 0; - max_payloadlen = nghttp2_min(datamax, frame->hd.length + NGHTTP2_MAX_PADLEN); + max_payloadlen = + nghttp2_min_size(datamax, frame->hd.length + NGHTTP2_MAX_PADLEN); padded_payloadlen = session_call_select_padding(session, frame, max_payloadlen); @@ -7997,7 +8002,7 @@ int32_t nghttp2_session_get_stream_remote_window_size(nghttp2_session *session, /* stream->remote_window_size can be negative when SETTINGS_INITIAL_WINDOW_SIZE is changed. */ - return nghttp2_max(0, stream->remote_window_size); + return nghttp2_max_int32(0, stream->remote_window_size); } int32_t nghttp2_session_get_remote_window_size(nghttp2_session *session) { diff --git a/lib/nghttp2_stream.c b/lib/nghttp2_stream.c index f1951f8..bf8b8c3 100644 --- a/lib/nghttp2_stream.c +++ b/lib/nghttp2_stream.c @@ -312,7 +312,7 @@ int32_t nghttp2_stream_dep_distributed_weight(nghttp2_stream *stream, int32_t weight) { weight = stream->weight * weight / stream->sum_dep_weight; - return nghttp2_max(1, weight); + return nghttp2_max_int32(1, weight); } #ifdef STREAM_DEP_DEBUG diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index f947969..72e6588 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -411,10 +411,10 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, if (window_size_increment > 0) { if (stream_id == 0) { session->consumed_size = - nghttp2_max(0, session->consumed_size - window_size_increment); + nghttp2_max_int32(0, session->consumed_size - window_size_increment); } else { stream->consumed_size = - nghttp2_max(0, stream->consumed_size - window_size_increment); + nghttp2_max_int32(0, stream->consumed_size - window_size_increment); } return nghttp2_session_add_window_update(session, 0, stream_id, |