Skip to content

Commit cab4c62

Browse files
committed
utf8_to_uv_msgs: Assert against both returning and warning
This asserts against the flags to the call of this function being contradictory, in that it is boths 1) to warn and/or die if anything goes wrong; and 2) not to warn under any circumstances but instead to return to the caller objects describing what it would have otherise warned. In a non-DEBUGGING build, the warn/die flags are ignored
1 parent b0ac0a6 commit cab4c62

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
@@ -1567,9 +1567,10 @@ to a variable which has been declared to be an C<AV*>, and into which the
15671567
function creates a new AV to store information, described below, about all the
15681568
malformations that were encountered.
15691569
1570-
If the flag C<UTF8_CHECK_ONLY> is passed, this parameter is ignored.
1571-
Otherwise, when this parameter is set, the flags C<UTF8_DIE_IF_MALFORMED> and
1572-
C<UTF8_FORCE_WARN_IF_MALFORMED> are ignored.
1570+
When this parameter is non-NULL, the C<UTF8_DIE_IF_MALFORMED> and
1571+
C<UTF8_FORCE_WARN_IF_MALFORMED> flags are asserted against in DEBUGGING builds,
1572+
and are ignored in non-DEBUGGING ones. The C<UTF8_CHECK_ONLY> flag is always
1573+
ignored.
15731574
15741575
What is considered a malformation is affected by C<flags>, the same as
15751576
described in C<L</utf8_to_uv_flags>>. No array element is generated for
@@ -1672,8 +1673,8 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
16721673
if (UNLIKELY(msgs)) {
16731674
*msgs = NULL;
16741675

1675-
/* The msgs parameter has higher priority than these flags */
1676-
flags &= ~(UTF8_DIE_IF_MALFORMED|UTF8_FORCE_WARN_IF_MALFORMED);
1676+
/* This form of the function has higher priority than this flag */
1677+
flags &= ~UTF8_CHECK_ONLY;
16771678
}
16781679

16791680
/* Each of the affected Hanguls starts with \xED */
@@ -2521,6 +2522,14 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
25212522
* returned; each case statement in the switch above does a
25222523
* continue if no message for it need be generated. */
25232524
if (msgs) {
2525+
2526+
/* It's illegal to call this with these flags, but we only fail
2527+
* in the unlikely event that it matters. Outside of DEBUGGING
2528+
* builds, those flags contradictory to this operation get
2529+
* ignored */
2530+
assert(! (flags & ( UTF8_DIE_IF_MALFORMED
2531+
|UTF8_FORCE_WARN_IF_MALFORMED)));
2532+
25242533
if (msgs_return == NULL) {
25252534
msgs_return = newAV();
25262535
}

0 commit comments

Comments
 (0)