]> git.kaiwu.me - nginx.git/commitdiff
QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).
authorSergey Kandaurov <pluknet@nginx.com>
Tue, 22 Dec 2020 09:04:16 +0000 (12:04 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Tue, 22 Dec 2020 09:04:16 +0000 (12:04 +0300)
src/event/ngx_event_quic_transport.c

index dc5ff9801551f129fb2bfaaae1b10d1c04c5172e..45c60c2555b0676e45e3d0a5600d498db194a168 100644 (file)
 #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 *end, size_t len, u_char *dst)
 }
 
 
+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)
 {