From: Jarkko Hietaniemi Date: Wed, 15 Nov 2000 02:48:37 +0000 (+0000) Subject: Quit utf8_to_uv() instantly if curlen == 0. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c443dc28412b09dfbd6dea23116ffd9554399c0;p=p5sagit%2Fp5-mst-13.2.git Quit utf8_to_uv() instantly if curlen == 0. p4raw-id: //depot/perl@7693 --- diff --git a/utf8.c b/utf8.c index 5d0fdc6..3cee2c2 100644 --- a/utf8.c +++ b/utf8.c @@ -195,6 +195,13 @@ Perl_utf8_to_uv(pTHX_ U8* s, STRLEN curlen, STRLEN* retlen, U32 flags) bool dowarn = ckWARN_d(WARN_UTF8); STRLEN expectlen = 0; + if (curlen == 0) { + if (dowarn) + Perl_warner(aTHX_ WARN_UTF8, + "Malformed UTF-8 character (an empty string)"); + goto malformed; + } + if (uv <= 0x7f) { /* Pure ASCII. */ if (retlen) *retlen = 1; @@ -210,7 +217,7 @@ Perl_utf8_to_uv(pTHX_ U8* s, STRLEN curlen, STRLEN* retlen, U32 flags) goto malformed; } - if ((uv >= 0xc0 && uv <= 0xfd && curlen >1 && s[1] < 0x80) && + if ((uv >= 0xc0 && uv <= 0xfd && curlen > 1 && s[1] < 0x80) && !(flags & UTF8_ALLOW_NON_CONTINUATION)) { if (dowarn) Perl_warner(aTHX_ WARN_UTF8, @@ -246,7 +253,7 @@ Perl_utf8_to_uv(pTHX_ U8* s, STRLEN curlen, STRLEN* retlen, U32 flags) if (dowarn) Perl_warner(aTHX_ WARN_UTF8, "Malformed UTF-8 character (%d byte%s, need %d)", - curlen, curlen > 1 ? "s" : "", expectlen); + curlen, curlen == 1 ? "" : "s", expectlen); goto malformed; } @@ -302,7 +309,7 @@ Perl_utf8_to_uv(pTHX_ U8* s, STRLEN curlen, STRLEN* retlen, U32 flags) if (dowarn) Perl_warner(aTHX_ WARN_UTF8, "Malformed UTF-8 character (%d byte%s, need %d)", - expectlen, expectlen > 1 ? "s": "", UNISKIP(uv)); + expectlen, expectlen == 1 ? "": "s", UNISKIP(uv)); goto malformed; }