From 5e2075c5192268e1a03c2e98d3d941dce155edd6 Mon Sep 17 00:00:00 2001 From: James Tirta Halim Date: Sat, 8 Jun 2024 10:46:19 +0700 Subject: [PATCH] refactor: apply on expand_shellcmd() --- src/nvim/cmdexpand.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 6aae3449be..27c327c339 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2994,10 +2994,12 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int bool did_curdir = false; // for ":set path=" and ":set tags=" halve backslashes for escaped space - char *pat = xstrdup(filepat); + size_t filepat_len = strlen(filepat); + char *pat = xmemdupz(filepat, filepat_len); + char *pat_e = pat + filepat_len; for (int i = 0; pat[i]; i++) { if (pat[i] == '\\' && pat[i + 1] == ' ') { - STRMOVE(pat + i, pat + i + 1); + memmove(pat + i, pat + i + 1, (size_t)(pat_e - (pat + i + 1) + 1)); } }