Skip to content

Commit

Permalink
fix JuliaLang#8341, parser hang on EOF during character byte sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 14, 2014
1 parent 8b25cca commit cfd60f1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/flisp/julia_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ value_t fl_skipws(value_t *args, u_int32_t nargs)
ios_t *s = fl_toiostream(args[0], "skip-ws");
int newlines = (args[1]!=FL_F);
uint32_t wc=0;
if (ios_peekutf8(s, &wc) == IOS_EOF)
return FL_EOF;
value_t skipped = FL_F;
while (!ios_eof(s) && (is_uws(wc) || is_bom(wc)) && (newlines || wc!=10)) {
skipped = FL_T;
ios_getutf8(s, &wc);
ios_peekutf8(s, &wc);
while (1) {
if (ios_peekutf8(s, &wc) == IOS_EOF) {
ios_getutf8(s, &wc); // to set EOF flag if this is a true EOF
if (!ios_eof(s))
lerror(symbol("error"), "incomplete character");
return FL_EOF;
}
if (!ios_eof(s) && (is_uws(wc) || is_bom(wc)) && (newlines || wc!=10)) {
skipped = FL_T;
ios_getutf8(s, &wc);
}
else {
break;
}
}
return skipped;
}
Expand Down

0 comments on commit cfd60f1

Please sign in to comment.