Have std/json look at args.src.is_closed() more

This commit is contained in:
Nigel Tao committed 2020-02-24 11:55:31 +11:00
1 parent 83ae50ce9b
commit c5b3a9e08e
3 files changed
+35

No files matched your search

+5
View File
@@ -17,6 +17,11 @@
/*
jsonptr is a JSON formatter (pretty-printer).
As of 2020-02-24, this program passes all 318 "test_parsing" cases from the
JSON test suite (https://github.com/nst/JSONTestSuite), an appendix to the
"Parsing JSON is a Minefield" article (http://seriot.ch/parsing_json.php) that
was first published on 2016-10-26 and updated on 2018-03-30.
This example program differs from most other example Wuffs programs in that it
is written in C++, not C.
+18
View File
@@ -18756,6 +18756,10 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
label_2_continue:;
while (true) {
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status =
wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
@@ -18842,6 +18846,11 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
if (a_src && a_src->meta.closed) {
status =
wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status = wuffs_base__make_status(
wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
@@ -18860,6 +18869,11 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto label_3_continue;
} else if (v_backslash == 117) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 6) {
if (a_src && a_src->meta.closed) {
status =
wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status = wuffs_base__make_status(
wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
@@ -18913,6 +18927,10 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
label_4_continue:;
while (true) {
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_json__error__bad_input);
goto exit;
}
status =
wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
+12
View File
@@ -157,6 +157,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
// before issuing a token with value_base_category 4.
while true {
if args.src.available() <= 0 {
if args.src.is_closed() {
return "#bad input"
}
yield? base."$short read"
continue
}
@@ -230,6 +233,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
assert args.dst.available() > 0
if args.src.available() < 2 {
if args.src.is_closed() {
return "#bad input"
}
yield? base."$short read"
string_length = 0
continue.string_loop
@@ -245,6 +251,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
} else if backslash == 0x75 { // 0x75 is 'u'.
if args.src.available() < 6 {
if args.src.is_closed() {
return "#bad input"
}
yield? base."$short read"
string_length = 0
continue.string_loop
@@ -291,6 +300,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
// The trailing '"' is filler.
while true {
if args.src.available() <= 0 {
if args.src.is_closed() {
return "#bad input"
}
yield? base."$short read"
continue
}