]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
fixed bug #37166: memp_sanity check loops itself
authorgoldsimon <goldsimon@gmx.de>
Wed, 22 Aug 2012 19:59:02 +0000 (21:59 +0200)
committergoldsimon <goldsimon@gmx.de>
Wed, 22 Aug 2012 19:59:02 +0000 (21:59 +0200)
CHANGELOG
src/core/memp.c

index b3f6890ff6c5e42cd3cef2a1529363dc12868419..8f7af0f8fc16d58adbd882defb711af132bed490 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -80,6 +80,9 @@ HISTORY
 
  ++ Bugfixes:
 
+  2012-08-22: Simon Goldschmidt
+  * memp.c: fixed bug #37166: memp_sanity check loops itself
+
   2012-08-13: Simon Goldschmidt
   * dhcp.c: fixed bug #36645: Calling dhcp_release before dhcp_start
     dereferences NULL
index 3496f682e4566c811a85f5e3c08b8196db0298a1..1323463e4450253ce70bdad8834b68a2c74be048 100644 (file)
@@ -179,19 +179,20 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1
 
 #if MEMP_SANITY_CHECK
 /**
- * Check that memp-lists don't form a circle
+ * Check that memp-lists don't form a circle, using "Floyd's cycle-finding algorithm".
  */
 static int
 memp_sanity(void)
 {
-  s16_t i, c;
-  struct memp *m, *n;
+  s16_t i;
+  struct memp *t, *h;
 
   for (i = 0; i < MEMP_MAX; i++) {
-    for (m = memp_tab[i]; m != NULL; m = m->next) {
-      c = 1;
-      for (n = memp_tab[i]; n != NULL; n = n->next) {
-        if (n == m && --c < 0) {
+    t = memp_tab[i];
+    if(t != NULL) {
+      for (h = t->next; (t != NULL) && (h != NULL); t = t->next,
+        h = (((h->next != NULL) && (h->next->next != NULL)) ? h->next->next : NULL)) {
+        if (t == h) {
           return 0;
         }
       }