From e9f2c446ed77eec13aad13748ac1b503b0cc3304 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 6 Mar 2017 12:25:21 -0700 Subject: [PATCH] utf8.c: Don't use Newx in decoding UTF-8 The bottom level UTF-8 decoding routine can be used during periods when using Newx is prohibited, as diagnosed by Dave Mitchell for perl #130921 (see that ticket for his explanation). This particular use of Newx was unnecessary, as it is just large enough to hold a single character, and that can be done by an automatic variable on the C stack. The variable is used only upon rare error conditions, but its only 14 bytes (15 on EBCDIC). --- utf8.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/utf8.c b/utf8.c index 89c8413..4949bf6 100644 --- a/utf8.c +++ b/utf8.c @@ -1079,6 +1079,8 @@ Perl_utf8n_to_uvchr_error(pTHX_ const U8 *s, U8 * adjusted_s0 = (U8 *) s0; U8 * adjusted_send = NULL; /* (Initialized to silence compilers' wrong warning) */ + U8 temp_char_buf[UTF8_MAXBYTES + 1]; /* Used to avoid a Newx in this + routine; see [perl #130921] */ UV uv_so_far = 0; /* (Initialized to silence compilers' wrong warning) */ PERL_ARGS_ASSERT_UTF8N_TO_UVCHR_ERROR; @@ -1245,10 +1247,7 @@ Perl_utf8n_to_uvchr_error(pTHX_ const U8 *s, I8_TO_NATIVE_UTF8(UTF_CONTINUATION_MARK)); } - Newx(adjusted_s0, OFFUNISKIP(min_uv) + 1, U8); - SAVEFREEPV((U8 *) adjusted_s0); /* Needed because we may not get - to free it ourselves if - warnings are made fatal */ + adjusted_s0 = temp_char_buf; adjusted_send = uvoffuni_to_utf8_flags(adjusted_s0, min_uv, 0); } } -- 1.8.3.1