Skip to content

Commit

Permalink
[perl #129106] Check for null PL_curcop in IN_LC()
Browse files Browse the repository at this point in the history
or, rather, in macros that it calls.

When exiting a string eval, the current cop may be freed, so PL_curcop
gets set to null.  With the -DC option, we may end up printfing NVs
during scope exit, so the locale macros used to make sure that the
locale is sane before converting the numbers to strings need to make
sure not to read PL_curcop->cop_hints when PL_curcop is null.

This used to crash with: ./miniperl -DC -e'eval "l/A"'

I’m not sure how to write a test for this, or even whether it’s worth
writing a test for -D, which often changes behaviour depending on
porters’ whims.
  • Loading branch information
Father Chrysostomos committed Sep 7, 2016
1 parent 1006894 commit 6b42170
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6002,7 +6002,8 @@ typedef struct am_table_short AMTS;

/* Returns TRUE if the plain locale pragma without a parameter is in effect
*/
# define IN_LOCALE_RUNTIME cBOOL(CopHINTS_get(PL_curcop) & HINT_LOCALE)
# define IN_LOCALE_RUNTIME (PL_curcop \
&& CopHINTS_get(PL_curcop) & HINT_LOCALE)

/* Returns TRUE if either form of the locale pragma is in effect */
# define IN_SOME_LOCALE_FORM_RUNTIME \
Expand All @@ -6023,7 +6024,7 @@ typedef struct am_table_short AMTS;

# define IN_LC_PARTIAL_COMPILETIME cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
# define IN_LC_PARTIAL_RUNTIME \
cBOOL(CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
(PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)

# define IN_LC_COMPILETIME(category) \
(IN_LC_ALL_COMPILETIME || (IN_LC_PARTIAL_COMPILETIME \
Expand Down

0 comments on commit 6b42170

Please sign in to comment.