@@ -1603,8 +1603,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
16031603 UV uv ;
16041604 SSize_t expectlen ; /* How long should this sequence be? */
16051605 SSize_t avail_len ; /* When input is too short, gives what that is */
1606- U32 discard_errors ; /* Used to save branches when 'errors' is NULL; this
1607- gets set and discarded */
16081606
16091607 dTHX ;
16101608
@@ -1650,14 +1648,10 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
16501648 possible_problems = 0 ;
16511649 expectlen = 0 ;
16521650 avail_len = 0 ;
1653- discard_errors = 0 ;
16541651
16551652 if (errors ) {
16561653 * errors = 0 ;
16571654 }
1658- else {
1659- errors = & discard_errors ;
1660- }
16611655
16621656 /* Accumulate the code point translation of the input byte sequence
16631657 * s0 .. e-1, looking for malformations.
@@ -1986,6 +1980,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
19861980
19871981 bool disallowed = FALSE;
19881982 const U32 orig_problems = possible_problems ;
1983+ U32 error_flags_return = 0 ;
19891984
19901985 /* The following macro returns 0 if no message needs to be generated
19911986 * for this problem even if everything else says to. Otherwise returns
@@ -2034,6 +2029,11 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
20342029
20352030 U32 this_flag_bit = this_problem ;
20362031
2032+ /* All cases but these two set this; it makes the cases simpler
2033+ * to do it here */
2034+ error_flags_return |= this_problem & ~( UTF8_GOT_PERL_EXTENDED
2035+ |UTF8_GOT_SUPER );
2036+
20372037 /* Turn off so next iteration doesn't retry this */
20382038 possible_problems &= ~this_problem ;
20392039
@@ -2056,8 +2056,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
20562056 break ;
20572057
20582058 case UTF8_GOT_EMPTY :
2059- * errors |= UTF8_GOT_EMPTY ;
2060-
20612059 if (! (flags & UTF8_ALLOW_EMPTY )) {
20622060
20632061 /* This so-called malformation is now treated as a bug in
@@ -2075,8 +2073,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
20752073 break ;
20762074
20772075 case UTF8_GOT_CONTINUATION :
2078- * errors |= UTF8_GOT_CONTINUATION ;
2079-
20802076 if (! (flags & UTF8_ALLOW_CONTINUATION )) {
20812077 disallowed = TRUE;
20822078 if (NEED_MESSAGE (WARN_UTF8 ,,)) {
@@ -2091,7 +2087,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
20912087 break ;
20922088
20932089 case UTF8_GOT_SHORT :
2094- * errors |= UTF8_GOT_SHORT ;
20952090 uv = UNICODE_REPLACEMENT ;
20962091
20972092 if (! (flags & UTF8_ALLOW_SHORT )) {
@@ -2110,7 +2105,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
21102105 break ;
21112106
21122107 case UTF8_GOT_NON_CONTINUATION :
2113- * errors |= UTF8_GOT_NON_CONTINUATION ;
21142108 uv = UNICODE_REPLACEMENT ;
21152109
21162110 if (! (flags & UTF8_ALLOW_NON_CONTINUATION )) {
@@ -2140,8 +2134,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
21402134 * this case are true */
21412135
21422136 if (flags & UTF8_WARN_SURROGATE ) {
2143- * errors |= UTF8_GOT_SURROGATE ;
2144-
21452137 if (NEED_MESSAGE (WARN_SURROGATE ,,)) {
21462138 pack_warn = packWARN (WARN_SURROGATE );
21472139
@@ -2161,7 +2153,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
21612153
21622154 if (flags & UTF8_DISALLOW_SURROGATE ) {
21632155 disallowed = TRUE;
2164- * errors |= UTF8_GOT_SURROGATE ;
21652156 }
21662157
21672158 break ;
@@ -2173,8 +2164,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
21732164 * this case are true */
21742165
21752166 if (flags & UTF8_WARN_NONCHAR ) {
2176- * errors |= UTF8_GOT_NONCHAR ;
2177-
21782167 if (NEED_MESSAGE (WARN_NONCHAR ,,)) {
21792168 /* The code above should have guaranteed that we don't
21802169 * get here with errors other than overlong */
@@ -2188,13 +2177,11 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
21882177
21892178 if (flags & UTF8_DISALLOW_NONCHAR ) {
21902179 disallowed = TRUE;
2191- * errors |= UTF8_GOT_NONCHAR ;
21922180 }
21932181
21942182 break ;
21952183
21962184 case UTF8_GOT_LONG :
2197- * errors |= UTF8_GOT_LONG ;
21982185
21992186 if (! (flags & UTF8_ALLOW_LONG_AND_ITS_VALUE )) {
22002187 uv = UNICODE_REPLACEMENT ;
@@ -2256,17 +2243,16 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22562243 /* Overflow means also got a super and are using Perl's
22572244 * extended UTF-8, but we handle all three cases here */
22582245 possible_problems &= ~(UTF8_GOT_SUPER |UTF8_GOT_PERL_EXTENDED );
2259- * errors |= UTF8_GOT_OVERFLOW ;
22602246 uv = UNICODE_REPLACEMENT ;
22612247
22622248 /* But the API says we flag all errors found */
22632249 if (flags & (UTF8_WARN_SUPER |UTF8_DISALLOW_SUPER )) {
2264- * errors |= UTF8_GOT_SUPER ;
2250+ error_flags_return |= UTF8_GOT_SUPER ;
22652251 }
22662252 if (flags
22672253 & (UTF8_WARN_PERL_EXTENDED |UTF8_DISALLOW_PERL_EXTENDED ))
22682254 {
2269- * errors |= UTF8_GOT_PERL_EXTENDED ;
2255+ error_flags_return |= UTF8_GOT_PERL_EXTENDED ;
22702256 }
22712257
22722258 /* Disallow if any of the three categories say to */
@@ -2312,7 +2298,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23122298 * warned about */
23132299
23142300 if (flags & UTF8_WARN_SUPER ) {
2315- * errors |= UTF8_GOT_SUPER ;
2301+ error_flags_return |= UTF8_GOT_SUPER ;
23162302
23172303 if (NEED_MESSAGE (WARN_NON_UNICODE ,,)) {
23182304 pack_warn = packWARN (WARN_NON_UNICODE );
@@ -2365,7 +2351,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23652351 if (flags & ( UTF8_WARN_PERL_EXTENDED
23662352 |UTF8_DISALLOW_PERL_EXTENDED ))
23672353 {
2368- * errors |= UTF8_GOT_PERL_EXTENDED ;
2354+ error_flags_return |= UTF8_GOT_PERL_EXTENDED ;
23692355
23702356 if (flags & UTF8_DISALLOW_PERL_EXTENDED ) {
23712357 disallowed = TRUE;
@@ -2374,7 +2360,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23742360 }
23752361
23762362 if (flags & UTF8_DISALLOW_SUPER ) {
2377- * errors |= UTF8_GOT_SUPER ;
2363+ error_flags_return |= UTF8_GOT_SUPER ;
23782364 disallowed = TRUE;
23792365 }
23802366
@@ -2409,6 +2395,10 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
24092395 * advance_p = curlen ;
24102396 }
24112397
2398+ if (errors ) {
2399+ * errors = error_flags_return ;
2400+ }
2401+
24122402 if (disallowed ) {
24132403 success = false;
24142404 uv = UNICODE_REPLACEMENT ;
0 commit comments