]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport rev 2.301 to the 2.1 maintenance branch.
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 20 Dec 2001 02:07:36 +0000 (02:07 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 20 Dec 2001 02:07:36 +0000 (02:07 +0000)
Add checks for stack underflow and overflow.

Python/ceval.c

index 72e4b6b7d697953162cecbc1a3e0979e77882525..0872c3e711a8ced6a1424a5a1261625175129f37 100644 (file)
@@ -402,7 +402,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
 #define BASIC_POP()    (*--stack_pointer)
 
 #ifdef LLTRACE
-#define PUSH(v)                (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
+#define PUSH(v)                { (void)(BASIC_PUSH(v), \
+                               lltrace && prtrace(TOP(), "push")); \
+                               assert(STACK_LEVEL() <= f->f_stacksize); }
 #define POP()          (lltrace && prtrace(TOP(), "pop"), BASIC_POP())
 #else
 #define PUSH(v)                BASIC_PUSH(v)
@@ -681,6 +683,8 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
        w = NULL;
 
        for (;;) {
+               assert(stack_pointer >= f->f_valuestack);       /* else underflow */
+               assert(STACK_LEVEL() <= f->f_stacksize);        /* else overflow */
                /* Do periodic things.  Doing this every time through
                   the loop would add too much overhead, so we do it
                   only every Nth instruction.  We also do it if