From a7addf98875555f48f30e7a9260f39a36a7b3e75 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Fri, 27 Jan 2017 13:25:02 -0500 Subject: Introduce some helpful macros for terminating strings, and fix overrun in dcgettext. --- interpret.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'interpret.h') diff --git a/interpret.h b/interpret.h index 191e1efb..13394e22 100644 --- a/interpret.h +++ b/interpret.h @@ -912,15 +912,14 @@ mod: sort_str = force_string(sort_str); if (sort_str->stlen > 0) { how_to_sort = sort_str->stptr; - save = sort_str->stptr[sort_str->stlen]; - sort_str->stptr[sort_str->stlen] = '\0'; + str_terminate(sort_str, save); saved_end = true; } } list = assoc_list(array, how_to_sort, SORTED_IN); if (saved_end) - sort_str->stptr[sort_str->stlen] = save; + str_restore(sort_str, save); arrayfor: getnode(r); @@ -1066,15 +1065,14 @@ match_re: fatal(_("indirect function call requires a simple scalar value")); t1 = force_string(t1); - save = t1->stptr[t1->stlen]; - t1->stptr[t1->stlen] = '\0'; + str_terminate(t1, save); if (t1->stlen > 0) { /* retrieve function definition node */ f = pc->func_body; if (f != NULL && strcmp(f->vname, t1->stptr) == 0) { /* indirect var hasn't been reassigned */ - t1->stptr[t1->stlen] = save; + str_restore(t1, save); ni = setup_frame(pc); JUMPTO(ni); /* Op_func */ } @@ -1099,12 +1097,12 @@ match_re: r = call_split_func(t1->stptr, arg_count); else r = the_func(arg_count); - t1->stptr[t1->stlen] = save; + str_restore(t1, save); PUSH(r); break; } else if (f->type != Node_func) { - t1->stptr[t1->stlen] = save; + str_restore(t1, save); if (f->type == Node_ext_func) { /* code copied from below, keep in sync */ INSTRUCTION *bc; @@ -1129,7 +1127,7 @@ match_re: pc->func_name); } pc->func_body = f; /* save for next call */ - t1->stptr[t1->stlen] = save; + str_restore(t1, save); ni = setup_frame(pc); JUMPTO(ni); /* Op_func */ -- cgit v1.2.3