[Olsr-dev] [olsrd] [PATCH v2 32/33] gateway: fix deserialisation of 0 in deserialize_gw_speed

Ferry Huberts (spam-protected)
Wed Jul 25 21:29:39 CEST 2012


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/gateway.c b/src/gateway.c
index bb97cbb..4239744 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -70,8 +70,17 @@ static bool v6gw_choosen_external;
  */
 static uint32_t
 deserialize_gw_speed(uint8_t value) {
-  uint32_t speed = (value >> 3)+1;
-  uint32_t exp = value & 7;
+  uint32_t speed;
+  uint32_t exp;
+
+  if (!value) {
+    /* 0 and 1 alias onto 0 during serialisation. We take 0 here to mean 0 and
+     * not 1 (since a bandwidth of 1 is no bandwidth at all really) */
+    return 0;
+  }
+
+  speed = (value >> 3)+1;
+  exp = value & 7;
 
   while (exp-- > 0) {
     speed *= 10;
-- 
1.7.11.2





More information about the Olsr-dev mailing list