cookie: fix loop invariant assert and exit on cookie exhaustion
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 18 Oct 2015 18:10:09 +0000 (20:10 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 18 Oct 2015 18:10:09 +0000 (20:10 +0200)
Fixes a Coverity warning

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/olsr_cookie.c

index dfd618a..0444082 100644 (file)
@@ -67,7 +67,12 @@ olsr_alloc_cookie(const char *cookie_name, olsr_cookie_type cookie_type)
     }
   }
 
-  assert(ci_index < COOKIE_ID_MAX);     /* increase COOKIE_ID_MAX */
+  /* 1 <= ci_index <= COOKIE_ID_MAX */
+
+  if (ci_index == COOKIE_ID_MAX) {
+    olsr_exit("No more cookies available", 1);
+    return NULL;
+  }
 
   ci = calloc(1, sizeof(struct olsr_cookie_info));
   cookies[ci_index] = ci;