From eb79c4a806f589badfca32e312a31ccef50ab0d7 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 17 Jan 2021 23:13:47 -0800 Subject: No longer allocatte memory for replacement string --- pattern.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pattern.c b/pattern.c index 94643f9..e600848 100644 --- a/pattern.c +++ b/pattern.c @@ -103,15 +103,11 @@ static pat_t *expand_choices(file_t *f, pat_t *first) if (!matchchar(&str, quote)) file_err(f, &repstr[-1], str, "This string doesn't have a closing quote."); - size_t replace_len = (size_t)(str-repstr-1); - const char *replacement = xcalloc(sizeof(char), replace_len+1); - memcpy((void*)replacement, repstr, replace_len); - pat_t *replacepat = first; first = new_pat(f, replacepat->start, BP_REPLACE); first->args.replace.pat = replacepat; - first->args.replace.text = replacement; - first->args.replace.len = replace_len; + first->args.replace.text = repstr; + first->args.replace.len = (size_t)(str-repstr-1); first->len = replacepat->len; first->end = str; } @@ -620,10 +616,6 @@ void destroy_pat(pat_t *pat) if (pat->args.capture.name) xfree(&pat->args.capture.name); break; - case BP_REPLACE: - if (pat->args.replace.text) - xfree(&pat->args.replace.text); - break; default: break; } } -- cgit v1.2.3