monitor_checkStack(): simplify and fix the degenerate case sp_size == 0
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 18 Aug 2008 16:52:36 +0000 (16:52 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 18 Aug 2008 16:52:36 +0000 (16:52 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1659 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/monitor.c

index 9630d3b392669fda4ad778578708d5221e3f96d5..e5ba5b321641c3795f45e755931aff4f92cbd32f 100644 (file)
@@ -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);