nnn

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1bc234b0eba9d9b385962a8c74a6e3a94397f67e
parent c87b67e07328ecfe18d3dc727d572bf0d1927ae0
Author: Arun <engineerarun@gmail.com>
Date:   Wed, 24 Nov 2021 22:48:02 +0530

Merge pull request #1244 from N-R-K/malloc_size

fix the malloc size in get_archive_cmd
Diffstat:
Msrc/nnn.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/nnn.c b/src/nnn.c @@ -765,6 +765,7 @@ static const char * const toks[] = { #define P_CPMVRNM 1 #define P_ARCHIVE 2 #define P_REPLACE 3 +#define P_ARCHIVE_CMD 4 static const char * const patterns[] = { SED" -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s", @@ -772,6 +773,7 @@ static const char * const patterns[] = { "%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'", "\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$", SED" -i 's|^%s\\(.*\\)$|%s\\1|' %s", + SED" -ze 's|^%s/||' '%s' | xargs -0 %s %s", }; /* Colors */ @@ -2721,18 +2723,15 @@ static void get_archive_cmd(char *cmd, const char *archive) static void archive_selection(const char *cmd, const char *archive, const char *curpath) { - /* The 70 comes from the string below */ - char *buf = (char *)malloc((70 + xstrlen(cmd) + xstrlen(archive) - + xstrlen(curpath) + xstrlen(selpath)) * sizeof(char)); + char *buf = malloc((xstrlen(patterns[P_ARCHIVE_CMD]) + xstrlen(cmd) + xstrlen(archive) + + xstrlen(curpath) + xstrlen(selpath)) * sizeof(char)); if (!buf) { DPRINTF_S(strerror(errno)); printwarn(NULL); return; } - snprintf(buf, CMD_LEN_MAX, - SED" -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, selpath, cmd, archive - ); + snprintf(buf, CMD_LEN_MAX, patterns[P_ARCHIVE_CMD], curpath, selpath, cmd, archive); spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI | F_CONFIRM); free(buf); }