Hi,
On line 598 of scope.c in perl 5.001 patchlevel 1m, the statement
savestack_ix -= SSPOPINT;
which expands to
savestack_ix -= (savestack[--savestack_ix].any_i32);
relies on the right-hand operand of the -= being evaluated before the
left-hand operand: evaluating the left-hand operand first decrements
savestack_ix by one less than intended.
I found that both HP-UX 7.0's and CLIX 3.1's compilers evaluate the left-hand
operand first. This doesn't appear to violate the ANSI C standard, which
allows any operand evaluation order for -=, according to the second edition of
K&R's "The C Programming Language".
Here's a patch to remove this dependency on operand evaluation order:
*** scope.c.orig Fri Jun 9 10:26:10 1995
--- scope.c Wed Sep 13 18:29:15 1995
***************
*** 594,602 ****
ptr = SSPOPPTR;
(*SSPOPDPTR)(ptr);
break;
! case SAVEt_REGCONTEXT:
! savestack_ix -= SSPOPINT; /* regexp must have croaked */
! break;
default:
croak("panic: leave_scope inconsistency");
}
--- 594,603 ----
ptr = SSPOPPTR;
(*SSPOPDPTR)(ptr);
break;
! case SAVEt_REGCONTEXT: {
! int pop_count = SSPOPINT; /* regexp must have croaked */
! savestack_ix -= pop_count;
! break; }
default:
croak("panic: leave_scope inconsistency");
}
Nick Duffek
nsd@bbc.com
On line 598 of scope.c in perl 5.001 patchlevel 1m, the statement
savestack_ix -= SSPOPINT;
which expands to
savestack_ix -= (savestack[--savestack_ix].any_i32);
relies on the right-hand operand of the -= being evaluated before the
left-hand operand: evaluating the left-hand operand first decrements
savestack_ix by one less than intended.
I found that both HP-UX 7.0's and CLIX 3.1's compilers evaluate the left-hand
operand first. This doesn't appear to violate the ANSI C standard, which
allows any operand evaluation order for -=, according to the second edition of
K&R's "The C Programming Language".
Here's a patch to remove this dependency on operand evaluation order:
*** scope.c.orig Fri Jun 9 10:26:10 1995
--- scope.c Wed Sep 13 18:29:15 1995
***************
*** 594,602 ****
ptr = SSPOPPTR;
(*SSPOPDPTR)(ptr);
break;
! case SAVEt_REGCONTEXT:
! savestack_ix -= SSPOPINT; /* regexp must have croaked */
! break;
default:
croak("panic: leave_scope inconsistency");
}
--- 594,603 ----
ptr = SSPOPPTR;
(*SSPOPDPTR)(ptr);
break;
! case SAVEt_REGCONTEXT: {
! int pop_count = SSPOPINT; /* regexp must have croaked */
! savestack_ix -= pop_count;
! break; }
default:
croak("panic: leave_scope inconsistency");
}
Nick Duffek
nsd@bbc.com