From 2ef3999d6d0e77861de8a049d1a8ac3e14135434 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 9 Apr 2020 17:24:39 +1000 Subject: [PATCH] Remove use of wuffs_base__token__link_prev --- example/jsonptr/jsonptr.cc | 13 ++++++++----- fuzz/c/std/json_fuzzer.c | 15 ++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/example/jsonptr/jsonptr.cc b/example/jsonptr/jsonptr.cc index f5d72aba..e4aa8a7a 100644 --- a/example/jsonptr/jsonptr.cc +++ b/example/jsonptr/jsonptr.cc @@ -838,7 +838,7 @@ handle_unicode_code_point(uint32_t ucp) { } const char* // -handle_token(wuffs_base__token t) { +handle_token(wuffs_base__token t, bool start_of_token_chain) { do { int64_t vbc = t.value_base_category(); uint64_t vbd = t.value_base_detail(); @@ -888,7 +888,7 @@ handle_token(wuffs_base__token t) { // Write preceding whitespace and punctuation, if it wasn't ']', '}' or a // continuation of a multi-token chain. - if (!t.link_prev()) { + if (start_of_token_chain) { if (g_ctx == context::in_dict_after_key) { TRY(write_dst(": ", g_flags.compact_output ? 1 : 2)); } else if (g_ctx != context::none) { @@ -962,7 +962,7 @@ handle_token(wuffs_base__token t) { return nullptr; case WUFFS_BASE__TOKEN__VBC__STRING: - if (!t.link_prev()) { + if (start_of_token_chain) { TRY(write_dst("\"", 1)); g_query.restart_fragment(in_dict_before_key() && g_query.is_at(g_depth)); @@ -986,7 +986,7 @@ handle_token(wuffs_base__token t) { goto after_value; case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: - if (!t.link_prev() || !t.link_next()) { + if (!t.link_next()) { return "main: internal error: unexpected unlinked token"; } TRY(handle_unicode_code_point(vbd)); @@ -1033,6 +1033,7 @@ const char* // main1(int argc, char** argv) { TRY(initialize_globals(argc, argv)); + bool start_of_token_chain = false; while (true) { wuffs_base__status status = g_dec.decode_tokens( &g_tok, &g_src, @@ -1048,10 +1049,12 @@ main1(int argc, char** argv) { // Skip filler tokens (e.g. whitespace). if (t.value() == 0) { + start_of_token_chain = !t.link_next(); continue; } - const char* z = handle_token(t); + const char* z = handle_token(t, start_of_token_chain); + start_of_token_chain = !t.link_next(); if (z == nullptr) { continue; } else if (z == g_eod) { diff --git a/fuzz/c/std/json_fuzzer.c b/fuzz/c/std/json_fuzzer.c index 9ccbbe19..c3ae16ee 100644 --- a/fuzz/c/std/json_fuzzer.c +++ b/fuzz/c/std/json_fuzzer.c @@ -85,7 +85,6 @@ typedef uint8_t stack_element; const char* // fuzz_one_token(wuffs_base__token t, - wuffs_base__token* prev_token, wuffs_base__io_buffer* src, size_t* ti, stack_element* stack, @@ -102,11 +101,6 @@ fuzz_one_token(wuffs_base__token t, return "fuzz: internal error: token high bit was not zero"; } - if (wuffs_base__token__link_next(prev_token) != - (wuffs_base__token__link_prev(&t))) { - return "fuzz: internal error: inconsistent link bits"; - } - int64_t vbc = wuffs_base__token__value_base_category(&t); uint64_t vbd = wuffs_base__token__value_base_detail(&t); @@ -290,7 +284,7 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint32_t hash_24_bits) { }), }); - wuffs_base__token prev_token = wuffs_base__make_token(0); + wuffs_base__token final_token = wuffs_base__make_token(0); uint32_t no_progress_count = 0; stack_element stack[STACK_SIZE]; @@ -335,12 +329,11 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint32_t hash_24_bits) { while (tok.meta.ri < tok.meta.wi) { // Inner loop. wuffs_base__token t = tok.data.ptr[tok.meta.ri++]; - const char* z = - fuzz_one_token(t, &prev_token, &src, &ti, &stack[0], &depth); + const char* z = fuzz_one_token(t, &src, &ti, &stack[0], &depth); if (z != NULL) { return z; } - prev_token = t; + final_token = t; } // Inner loop. // ---- @@ -375,7 +368,7 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint32_t hash_24_bits) { if (depth != 0) { return "fuzz: internal error: decoded OK but final depth was not zero"; - } else if (wuffs_base__token__link_next(&prev_token)) { + } else if (wuffs_base__token__link_next(&final_token)) { return "fuzz: internal error: decoded OK but final token had link_next"; } return NULL;