Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6d14da

Browse files
committed
SF bug #494668: PUSH() should assert-fail on overflow.
eval_frame(): Added asserts to the top of the eval loop, to verify that the eval stack pointer is in bounds, plus some comments.
1 parent 81b61bd commit b6d14da

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Python/ceval.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ eval_frame(PyFrameObject *f)
497497
#ifdef DXPAIRS
498498
int lastopcode = 0;
499499
#endif
500-
PyObject **stack_pointer;
500+
PyObject **stack_pointer; /* Next free slot in value stack */
501501
register unsigned char *next_instr;
502502
register int opcode=0; /* Current opcode */
503503
register int oparg=0; /* Current opcode argument, if any */
@@ -586,7 +586,7 @@ eval_frame(PyFrameObject *f)
586586
next_instr = first_instr + f->f_lasti;
587587
stack_pointer = f->f_stacktop;
588588
assert(stack_pointer != NULL);
589-
f->f_stacktop = NULL;
589+
f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
590590

591591
if (tstate->use_tracing) {
592592
if (tstate->c_tracefunc != NULL) {
@@ -634,6 +634,8 @@ eval_frame(PyFrameObject *f)
634634
w = NULL;
635635

636636
for (;;) {
637+
assert(stack_pointer >= f->f_valuestack); /* else underflow */
638+
assert(STACK_LEVEL() <= f->f_stacksize); /* else overflow */
637639
/* Do periodic things. Doing this every time through
638640
the loop would add too much overhead, so we do it
639641
only every Nth instruction. We also do it if

0 commit comments

Comments
 (0)