mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
Merge pull request #1244 from N-R-K/malloc_size
fix the malloc size in get_archive_cmd
This commit is contained in:
commit
1bc234b0eb
|
@ -765,6 +765,7 @@ static const char * const toks[] = {
|
||||||
#define P_CPMVRNM 1
|
#define P_CPMVRNM 1
|
||||||
#define P_ARCHIVE 2
|
#define P_ARCHIVE 2
|
||||||
#define P_REPLACE 3
|
#define P_REPLACE 3
|
||||||
|
#define P_ARCHIVE_CMD 4
|
||||||
|
|
||||||
static const char * const patterns[] = {
|
static const char * const patterns[] = {
|
||||||
SED" -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s",
|
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'",
|
"%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'",
|
||||||
"\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$",
|
"\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$",
|
||||||
SED" -i 's|^%s\\(.*\\)$|%s\\1|' %s",
|
SED" -i 's|^%s\\(.*\\)$|%s\\1|' %s",
|
||||||
|
SED" -ze 's|^%s/||' '%s' | xargs -0 %s %s",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Colors */
|
/* Colors */
|
||||||
|
@ -2721,8 +2723,7 @@ static void get_archive_cmd(char *cmd, const char *archive)
|
||||||
|
|
||||||
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 70 comes from the string below */
|
char *buf = malloc((xstrlen(patterns[P_ARCHIVE_CMD]) + xstrlen(cmd) + xstrlen(archive)
|
||||||
char *buf = (char *)malloc((70 + 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,9 +2731,7 @@ static void archive_selection(const char *cmd, const char *archive, const char *
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX, patterns[P_ARCHIVE_CMD], 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue