diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2000-11-15 02:48:37 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-11-15 02:48:37 +0000 |
commit | 0c443dc28412b09dfbd6dea23116ffd9554399c0 (patch) | |
tree | 3064dfb0b542ab51fb8ee5393d89681f61630aec /utf8.c | |
parent | 240a5ecf567cf5d54bbf1144872c0b74f2a322b7 (diff) | |
download | perl-0c443dc28412b09dfbd6dea23116ffd9554399c0.tar.gz |
Quit utf8_to_uv() instantly if curlen == 0.
p4raw-id: //depot/perl@7693
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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; } |