From: Willy Tarreau Date: Wed, 5 Feb 2020 14:28:55 +0000 (+0100) Subject: CLEANUP: hpack: remove a redundant test in the decoder X-Git-Tag: v2.2-dev2~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=077d366ef7d09d2284ddea9f787cfce4ed4d3ba0;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/hpack-dec.c b/src/hpack-dec.c index 7f3e7624b9..a721fadc46 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--;