From f151e1b0c2521ce838cdee6f32014296185e7dc9 Mon Sep 17 00:00:00 2001 From: Jaap Keuter Date: Thu, 23 Dec 2021 14:27:30 +0000 Subject: Refactor VARINT handling --- epan/tvbuff.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'epan/tvbuff.c') diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 26f69cf473..9c411fdad3 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -4486,7 +4486,9 @@ tvb_get_varint(tvbuff_t *tvb, guint offset, guint maxlen, guint64 *value, const { *value = 0; - if (encoding & ENC_VARINT_PROTOBUF) { + switch (encoding & ENC_VARINT_MASK) { + case ENC_VARINT_PROTOBUF: + { guint i; guint64 b; /* current byte */ @@ -4499,7 +4501,11 @@ tvb_get_varint(tvbuff_t *tvb, guint offset, guint maxlen, guint64 *value, const return i + 1; } } - } else if (encoding & ENC_VARINT_ZIGZAG) { + break; + } + + case ENC_VARINT_ZIGZAG: + { guint i; guint64 b; /* current byte */ @@ -4513,9 +4519,11 @@ tvb_get_varint(tvbuff_t *tvb, guint offset, guint maxlen, guint64 *value, const return i + 1; } } + break; } - else if (encoding & ENC_VARINT_QUIC) { + case ENC_VARINT_QUIC: + { /* calculate variable length */ *value = tvb_get_guint8(tvb, offset); switch((*value) >> 6) { @@ -4535,7 +4543,11 @@ tvb_get_varint(tvbuff_t *tvb, guint offset, guint maxlen, guint64 *value, const ws_assert_not_reached(); break; } + break; + } + default: + DISSECTOR_ASSERT_NOT_REACHED(); } return 0; /* 10 bytes scanned, but no bytes' msb is zero */ -- cgit v1.2.3