From 5e3cadc52de524b2059fc95e46819c079dd957d9 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Wed, 30 Dec 2020 11:20:15 +0000 Subject: [PATCH] Avoid accessing unowned memory --- src/scanner.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scanner.cc b/src/scanner.cc index 5116fe8..16e0af0 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -655,9 +655,10 @@ struct Scanner { bool allow_comment = !(VLD[R_DQT_STR_CTN] || VLD[BR_DQT_STR_CTN] || VLD[R_SQT_STR_CTN] || VLD[BR_SQT_STR_CTN]); - int16_t *ind_ptr = &ind_len_stk.back(); - int16_t cur_ind = *ind_ptr--; - int16_t prt_ind = *ind_ptr; + vector::reverse_iterator ind_ptr = ind_len_stk.rbegin(); + vector::reverse_iterator ind_end = ind_len_stk.rend(); + int16_t cur_ind = *ind_ptr++; + int16_t prt_ind = ind_ptr == ind_end ? -1 : *ind_ptr; int16_t cur_ind_typ = ind_typ_stk.back(); bool has_tab_ind = false;