Skip to content

Commit

Permalink
[perl #130814] update pointer into PL_linestr after lookahead
Browse files Browse the repository at this point in the history
Looking ahead for the "Missing $ on loop variable" diagnostic can reallocate
PL_linestr, invalidating our pointer. Save the offset so we can update it
in that case.
  • Loading branch information
hvds committed Feb 21, 2017
1 parent d7186ad commit 90f2cc9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions toke.c
Expand Up @@ -7913,6 +7913,7 @@ Perl_yylex(pTHX)
&& isIDFIRST_lazy_if_safe(s, PL_bufend, UTF))
{
char *p = s;
SSize_t s_off = s - SvPVX(PL_linestr);

if ((PL_bufend - p) >= 3
&& strEQs(p, "my") && isSPACE(*(p + 2)))
Expand All @@ -7930,6 +7931,9 @@ Perl_yylex(pTHX)
}
if (*p != '$' && *p != '\\')
Perl_croak(aTHX_ "Missing $ on loop variable");

/* The buffer may have been reallocated, update s */
s = SvPVX(PL_linestr) + s_off;
}
OPERATOR(FOR);

Expand Down

0 comments on commit 90f2cc9

Please sign in to comment.