From 10362a70dfaaffe19a40df08171d504dc45f126f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 21 Dec 2020 20:39:41 -0800 Subject: [PATCH] Clean up parse_error_offset_source_start Use range-based for loops and relax the requirement that we have an error list. --- src/parse_tree.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 52bb3ea9b..3dc16ff26 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -134,14 +134,11 @@ wcstring parse_error_t::describe(const wcstring &src, bool is_interactive) const } void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) { - assert(errors != nullptr); - if (amt > 0) { - size_t i, max = errors->size(); - for (i = 0; i < max; i++) { - parse_error_t *error = &errors->at(i); + if (amt > 0 && errors != nullptr) { + for (parse_error_t &error : *errors) { // Preserve the special meaning of -1 as 'unknown'. - if (error->source_start != SOURCE_LOCATION_UNKNOWN) { - error->source_start += amt; + if (error.source_start != SOURCE_LOCATION_UNKNOWN) { + error.source_start += amt; } } }