[Olsr-dev] [olsrd] [PATCH v3 1/2] gateway: fix serialize_gw_speed

Ferry Huberts (spam-protected)
Thu Jul 19 09:54:52 CEST 2012


From: Ferry Huberts <(spam-protected)>

Values over 320000000 would serialize to 0, which is not correct,
since they should be clipped to the maximum value of the
serialization range.

v2: unchanged, sent with another patch

v3: values 100000000 and 200000000 would result in an exponent of 8,
    which is out-of-range for the exponent.

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

diff --git a/src/gateway.c b/src/gateway.c
index 048a7cb..ee122b7 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -62,11 +62,15 @@ static uint8_t
 serialize_gw_speed(uint32_t speed) {
   uint8_t exp = 0;
 
-  if (speed == 0 || speed > 320000000) {
+  if (speed == 0) {
     return 0;
   }
 
-  while (speed > 32 || (speed % 10) == 0) {
+  if (speed > 320000000) {
+    return 0xff;
+  }
+
+  while ((speed > 32 || (speed % 10) == 0) && exp < 7) {
     speed /= 10;
     exp ++;
   }
-- 
1.7.10.4





More information about the Olsr-dev mailing list