changeset 8671:5247461c17e1 quic

QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 22 Dec 2020 12:04:16 +0300
parents b14338acbf9d
children 13c537def699
files src/event/ngx_event_quic_transport.c
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/event/ngx_event_quic_transport.c
+++ b/src/event/ngx_event_quic_transport.c
@@ -55,16 +55,11 @@
 #define ngx_quic_write_uint32_aligned(p, s)                                   \
     (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
 
-#define ngx_quic_varint_len(value)                                            \
-     ((value) <= 63 ? 1                                                       \
-     : ((uint32_t) value) <= 16383 ? 2                                        \
-     : ((uint64_t) value) <= 1073741823 ?  4                                  \
-     : 8)
-
 #define NGX_QUIC_VERSION(c)       (0xff000000 + (c))
 
 
 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out);
+static ngx_uint_t ngx_quic_varint_len(uint64_t value);
 static void ngx_quic_build_int(u_char **pos, uint64_t value);
 
 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value);
@@ -236,6 +231,20 @@ ngx_quic_copy_bytes(u_char *pos, u_char 
 }
 
 
+static ngx_uint_t
+ngx_quic_varint_len(uint64_t value)
+{
+    ngx_uint_t  bits;
+
+    bits = 0;
+    while (value >> ((8 << bits) - 2)) {
+        bits++;
+    }
+
+    return 1 << bits;
+}
+
+
 static void
 ngx_quic_build_int(u_char **pos, uint64_t value)
 {