From 077d366ef7d09d2284ddea9f787cfce4ed4d3ba0 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 5 Feb 2020 15:28:55 +0100 Subject: [PATCH] CLEANUP: hpack: remove a redundant test in the decoder As reported in issue #485 the test for !len at the end of the loop in get_var_int() is useless since it was already done inside the loop. Actually the code is more readable if we remove the first one so let's do this instead. The resulting code is exactly the same since the compiler already optimized the test away. --- src/hpack-dec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/hpack-dec.c b/src/hpack-dec.c index 7f3e7624b..a721fadc4 100644 --- a/src/hpack-dec.c +++ b/src/hpack-dec.c @@ -65,11 +65,7 @@ static uint32_t get_var_int(const uint8_t **raw_in, uint32_t *len_in, int b) if (ret != (uint32_t)((1 << b) - 1)) goto end; - while (1) { - if (!len) - goto too_short; - if (!(*raw & 128)) - break; + while (len && (*raw & 128)) { ret += ((uint32_t)(*raw++) & 127) << shift; shift += 7; len--;