From: bernie Date: Mon, 18 Aug 2008 16:52:36 +0000 (+0000) Subject: monitor_checkStack(): simplify and fix the degenerate case sp_size == 0 X-Git-Tag: 2.0.0~275 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=1815e3dc48701e41cd28cd6241398b972bedba50;p=bertos.git monitor_checkStack(): simplify and fix the degenerate case sp_size == 0 git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1659 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/kern/monitor.c b/bertos/kern/monitor.c index 9630d3b3..e5ba5b32 100644 --- a/bertos/kern/monitor.c +++ b/bertos/kern/monitor.c @@ -83,28 +83,27 @@ size_t monitor_checkStack(cpustack_t *stack_base, size_t stack_size) cpustack_t *beg; cpustack_t *cur; cpustack_t *end; + int inc; size_t sp_free; + beg = stack_base; - end = stack_base + stack_size / sizeof(cpustack_t) - 1; + end = stack_base + stack_size / sizeof(cpustack_t); + inc = +1; if (CPU_STACK_GROWS_UPWARD) { - cur = beg; - beg = end; - end = cur; + SWAP(beg, end); + inc = -1; } cur = beg; - while (cur != end) + while (beg != end) { if (*cur != CONFIG_KERN_STACKFILLCODE) break; - if (CPU_STACK_GROWS_UPWARD) - cur--; - else - cur++; + cur += inc; } sp_free = ABS(cur - beg) * sizeof(cpustack_t);