Skip to content

Commit

Permalink
utf8::upgrade: Don't coerce undef arg
Browse files Browse the repository at this point in the history
This fixes GH Perl#20419
  • Loading branch information
khwilliamson committed Nov 2, 2022
1 parent fce4124 commit b1dbe27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ for(__PACKAGE__) {
eval { utf8::upgrade($_) };
is $@, "", 'no error with utf8::upgrade on read-only COW';
}

is(utf8::upgrade(undef), undef, "Returns undef for undef input"); # GH #20419

# This one croaks, but not because the scalar is read-only
eval "package \x{100};\n" . <<'END'
for(__PACKAGE__) {
Expand Down
16 changes: 13 additions & 3 deletions universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,21 @@ XS(XS_utf8_upgrade)
croak_xs_usage(cv, "sv");
else {
SV * const sv = ST(0);
STRLEN RETVAL;
STRLEN RETVAL = 0;
dXSTARG;

RETVAL = sv_utf8_upgrade(sv);
XSprePUSH; PUSHi((IV)RETVAL);
XSprePUSH;
if (UNLIKELY(! sv)) {
XSRETURN_UNDEF;
}

SvGETMAGIC(sv);
if (UNLIKELY(! SvOK(sv))) {
XSRETURN_UNDEF;
}

RETVAL = sv_utf8_upgrade_nomg(sv);
PUSHi( (IV) RETVAL);
}
XSRETURN(1);
}
Expand Down

0 comments on commit b1dbe27

Please sign in to comment.