diff --git a/universal.c b/universal.c index 119117e818a4..0b12a231b56e 100644 --- a/universal.c +++ b/universal.c @@ -593,10 +593,13 @@ 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); + if (LIKELY(sv && SvANY(sv))) { + RETVAL = sv_utf8_upgrade(sv); + } + XSprePUSH; PUSHi((IV)RETVAL); } XSRETURN(1);