use a macro for the format string

this makes things slightly more robust as changing the string inside the
macro would automatically change the malloc size.
This commit is contained in:
NRK 2021-11-24 22:06:05 +06:00
parent f7091f78e5
commit 578e6d1aaa

View file

@ -2719,10 +2719,10 @@ static void get_archive_cmd(char *cmd, const char *archive)
xstrsncpy(cmd, archive_cmd[i], ARCHIVE_CMD_LEN); xstrsncpy(cmd, archive_cmd[i], ARCHIVE_CMD_LEN);
} }
#define CMD_FMT " -ze 's|^%s/||' '%s' | xargs -0 %s %s"
static void archive_selection(const char *cmd, const char *archive, const char *curpath) static void archive_selection(const char *cmd, const char *archive, const char *curpath)
{ {
/* The 38 comes from the format string below */ char *buf = malloc((sizeof(CMD_FMT) + xstrlen(cmd) + xstrlen(archive)
char *buf = malloc((38 + xstrlen(cmd) + xstrlen(archive)
+ xstrlen(curpath) + xstrlen(selpath)) * sizeof(char)); + xstrlen(curpath) + xstrlen(selpath)) * sizeof(char));
if (!buf) { if (!buf) {
DPRINTF_S(strerror(errno)); DPRINTF_S(strerror(errno));
@ -2730,12 +2730,11 @@ static void archive_selection(const char *cmd, const char *archive, const char *
return; return;
} }
snprintf(buf, CMD_LEN_MAX, snprintf(buf, CMD_LEN_MAX, SED CMD_FMT, curpath, selpath, cmd, archive);
SED" -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, selpath, cmd, archive
);
spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI | F_CONFIRM); spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI | F_CONFIRM);
free(buf); free(buf);
} }
#undef CMD_FMT
static void write_lastdir(const char *curpath, const char *outfile) static void write_lastdir(const char *curpath, const char *outfile)
{ {