From 1815e3dc48701e41cd28cd6241398b972bedba50 Mon Sep 17 00:00:00 2001 From: bernie Date: Mon, 18 Aug 2008 16:52:36 +0000 Subject: [PATCH] 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 --- bertos/kern/monitor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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); -- 2.25.1