diff --git a/CHANGELOG b/CHANGELOG index 3b292e07..e7c4aa8f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -66,6 +66,9 @@ HISTORY ++ Bugfixes: + 2012-08-22: Simon Goldschmidt + * memp.c: fixed bug #37166: memp_sanity check loops itself + 2012-05-08: Simon Goldschmidt * tcp_out.c: fixed bug: #36380 unsent_oversize mismatch in 1.4.1RC1 (this was a debug-check issue only) diff --git a/src/core/memp.c b/src/core/memp.c index 4da879a5..9f680e24 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -176,19 +176,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; } }