From d0642f93b778ff38b01d1e70a93ef15d0a7f57a4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 28 Jan 2022 09:39:24 +0100 Subject: [PATCH] BUILD: tree-wide: mark a few numeric constants as explicitly long long At a few places in the code the switch/case ond flags are tested against 64-bit constants without explicitly being marked as long long. Some 32-bit compilers complain that the constant is too large for a long, and other likely always use long long there. Better fix that as it's uncertain what others which do not complain do. It may be backported to avoid doubts on uncommon platforms if needed, as it touches very few areas. (cherry picked from commit 8f0b4e97e78f62eac43e240155192131e7c6d072) [wt: 2.5 was reporting warnings on a 32-bit platform with gcc-4.4] Signed-off-by: Willy Tarreau --- include/haproxy/h1.h | 2 +- include/haproxy/intops.h | 18 +++++++++--------- src/h1_htx.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/haproxy/h1.h b/include/haproxy/h1.h index 1891c81..8f52059 100644 --- a/include/haproxy/h1.h +++ b/include/haproxy/h1.h @@ -278,7 +278,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s if (unlikely(++ptr >= end)) ptr = b_orig(buf); chunk = (chunk << 4) + c; - if (unlikely(chunk & 0xF0000000000000)) { + if (unlikely(chunk & 0xF0000000000000ULL)) { /* Don't get more than 13 hexa-digit (2^52 - 1) to never fed possibly * bogus values from languages that use floats for their integers */ diff --git a/include/haproxy/intops.h b/include/haproxy/intops.h index a812874..86b02aa 100644 --- a/include/haproxy/intops.h +++ b/include/haproxy/intops.h @@ -396,15 +396,15 @@ static inline unsigned int __read_uint(const char **s, const char *end) static inline int __varint_bytes(uint64_t v) { switch (v) { - case 0x0000000000000000 ... 0x00000000000000ef: return 1; - case 0x00000000000000f0 ... 0x00000000000008ef: return 2; - case 0x00000000000008f0 ... 0x00000000000408ef: return 3; - case 0x00000000000408f0 ... 0x00000000020408ef: return 4; - case 0x00000000020408f0 ... 0x00000001020408ef: return 5; - case 0x00000001020408f0 ... 0x00000081020408ef: return 6; - case 0x00000081020408f0 ... 0x00004081020408ef: return 7; - case 0x00004081020408f0 ... 0x00204081020408ef: return 8; - case 0x00204081020408f0 ... 0x10204081020408ef: return 9; + case 0x0000000000000000ULL ... 0x00000000000000efULL: return 1; + case 0x00000000000000f0ULL ... 0x00000000000008efULL: return 2; + case 0x00000000000008f0ULL ... 0x00000000000408efULL: return 3; + case 0x00000000000408f0ULL ... 0x00000000020408efULL: return 4; + case 0x00000000020408f0ULL ... 0x00000001020408efULL: return 5; + case 0x00000001020408f0ULL ... 0x00000081020408efULL: return 6; + case 0x00000081020408f0ULL ... 0x00004081020408efULL: return 7; + case 0x00004081020408f0ULL ... 0x00204081020408efULL: return 8; + case 0x00204081020408f0ULL ... 0x10204081020408efULL: return 9; default: return 10; } } diff --git a/src/h1_htx.c b/src/h1_htx.c index 331b79d..3d74a4c 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -642,7 +642,7 @@ static size_t h1_parse_full_contig_chunks(struct h1m *h1m, struct htx **dsthtx, /* Update current chunk size */ chksz = (chksz << 4) + c; - if (unlikely(chksz & 0xF0000000000000)) { + if (unlikely(chksz & 0xF0000000000000ULL)) { /* Don't get more than 13 hexa-digit (2^52 - 1) * to never fed possibly bogus values from * languages that use floats for their integers -- 1.7.10.4