From 4e2b2b942daa4206ec44c66e59863670dfe3fde4 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 22:28:25 +0200 Subject: low risk, potentially varint overflow bug patched thanks to BBR --- src/common/varint.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/varint.h b/src/common/varint.h index 5a73c2746..57386597a 100644 --- a/src/common/varint.h +++ b/src/common/varint.h @@ -36,7 +36,7 @@ #include #include /*! \file varint.h - * \breif provides the implementation of varint's + * \brief provides the implementation of varint's * * The representation of varints is rather odd. The first bit of each * octet is significant, it represents wheter there is another part @@ -52,6 +52,29 @@ namespace tools { + template + size_t get_varint_packed_size(T v) + { + if(v <= 127) + return 1; + else if(v <= 16383) + return 2; + else if(v <= 2097151) + return 3; + else if(v <= 268435455) + return 4; + else if(v <= 34359738367) + return 5; + else if(v <= 4398046511103) + return 6; + else if(v <= 4398046511103) + return 6; + else if(v <= 562949953421311) + return 7; + else + return 8; + } + /*! \brief Error codes for varint */ enum { -- cgit v1.2.3