Skip to content

Commit

Permalink
Set PERLIO_F_ERROR on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Apr 7, 2012
1 parent 8e21d58 commit 0967f9c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/PerlIO/utf8_strict.xs
Expand Up @@ -77,7 +77,8 @@ static void report_noncharacter(pTHX_ UV usv) {
Perl_croak(aTHX_ fmt, usv);
}

static STRLEN validate(pTHX_ const U8 *buf, const U8 *end, const int flags, const bool eof) {
static STRLEN validate(pTHX_ const U8 *buf, const U8 *end, const int flags, PerlIO* handle) {
const bool eof = PerlIO_eof(handle);
const U8 *cur = buf;
const U8 *end4 = end - 4;
STRLEN skip = 0;
Expand Down Expand Up @@ -149,13 +150,15 @@ static STRLEN validate(pTHX_ const U8 *buf, const U8 *end, const int flags, cons
illformed:
if (!skip)
skip = skip_sequence(cur, end - cur);
PerlIOBase(handle)->flags |= PERLIO_F_ERROR;
report_illformed(aTHX_ cur, skip, eof);

noncharacter:
if (v < 0x10000)
v = (v & 0x3F) | (v & 0x1F00) >> 2;
else
v = (v & 0x3F) | (v & 0x1F00) >> 2 | (v & 0x0F0000) >> 4;
PerlIOBase(handle)->flags |= PERLIO_F_ERROR;
report_noncharacter(aTHX_ v);
}

Expand Down Expand Up @@ -294,7 +297,7 @@ static IV PerlIOUnicode_fill(pTHX_ PerlIO* f) {
}
end = b->buf + read_bytes;
b->end = b->buf;
b->end += validate(aTHX_ (const U8 *)b->end, (const U8 *)end, u->flags, PerlIO_eof(n));
b->end += validate(aTHX_ (const U8 *)b->end, (const U8 *)end, u->flags, n);
if (b->end < end) {
size_t len = b->buf + read_bytes - b->end;
Copy(b->end, u->leftovers, len, char);
Expand Down

0 comments on commit 0967f9c

Please sign in to comment.