Skip to content

Commit 6982901

Browse files
committed
utf8_to_uv_msgs: Error if tries to both return and warn
This panics if the flags to the call of this function are contradictory, in that it is both to warn if anything goes wrong, and not to warn under any circumstances but instead to return to the caller objects describing what it would warn. I'm unsure what the proper thing is to do here. This commit makes this a run time panic when the conflict actually happens, but not until. This is along the lines of you can divide, but only when the divisor is 0 is an error raised. I think this is better than croaking if there is even the possibility of a problem. But I'm not sure. And should it be a panic or just a fatal error, or just a warning and we choose probably to die if one of the flags says to die, or to both warn and return if one of the flags says just warn.
1 parent 5a80af9 commit 6982901

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

utf8.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,9 +1541,9 @@ to a variable which has been declared to be an C<AV*>, and into which the
15411541
function creates a new AV to store information, described below, about all
15421542
the malformations that were encountered.
15431543
1544-
If the flag C<UTF8_CHECK_ONLY> is passed, this parameter is ignored.
1545-
Otherwise, when this parameter is set, the flags C<UTF8_DIE_IF_MALFORMED> and
1546-
C<UTF8_FORCE_WARN_IF_MALFORMED> are ignored.
1544+
When this parameter is non-NULL, the C<UTF8_DIE_IF_MALFORMED> and
1545+
C<UTF8_FORCE_WARN_IF_MALFORMED> flags are forbidden, and generate a runtime
1546+
error. The C<UTF8_CHECK_ONLY> flag is ignored.
15471547
15481548
What is considered a malformation is affected by C<flags>, the same as
15491549
described in C<L</utf8_to_uv_flags>>. No array element is generated for
@@ -1640,8 +1640,8 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
16401640
if (UNLIKELY(msgs)) {
16411641
*msgs = NULL;
16421642

1643-
/* The msgs parameter has higher priority than these flags */
1644-
flags &= ~(UTF8_DIE_IF_MALFORMED|UTF8_FORCE_WARN_IF_MALFORMED);
1643+
/* This form of the function has higher priority than this flag */
1644+
flags &= ~UTF8_CHECK_ONLY;
16451645
}
16461646

16471647
/* Each of the affected Hanguls starts with \xED */
@@ -2493,6 +2493,15 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
24932493
* returned; each case statement in the switch above does a
24942494
* continue if no message for it need be generated. */
24952495
if (msgs) {
2496+
if (flags &
2497+
(UTF8_DIE_IF_MALFORMED|UTF8_FORCE_WARN_IF_MALFORMED))
2498+
{
2499+
Perl_croak_nocontext(
2500+
"panic: utf8_to_uv_msgs() does not accept either of"
2501+
" the UTF8_DIE_IF_MALFORMED or"
2502+
" UTF8_FORCE_WARN_IF_MALFORMED flags");
2503+
}
2504+
24962505
if (msgs_return == NULL) {
24972506
msgs_return = newAV();
24982507
}

0 commit comments

Comments
 (0)