]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: hpack: remove a redundant test in the decoder
authorWilly Tarreau <w@1wt.eu>
Wed, 5 Feb 2020 14:28:55 +0000 (15:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 Feb 2020 14:39:08 +0000 (15:39 +0100)
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

index 7f3e7624b96951d4bf9187f69250c23a492a5ec2..a721fadc468e075c76a69a466e37788119e40051 100644 (file)
@@ -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--;