aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-02-29 12:56:10 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-02-29 12:56:10 +0530
commit0d7d0ca7dbd7c9c297d51f39d06d08181305fc5f (patch)
tree874e33456830a0c965fd3e76a93e056ba90e8f9e /src
parent5198c6286329889cf65fce766675aeeac73eae1a (diff)
downloadnnn-0d7d0ca7dbd7c9c297d51f39d06d08181305fc5f.tar.gz
realpath allocates memory
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 4511587..d939eb6 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -2926,12 +2926,10 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, ushort *items)
return FALSE;
}
- if (nextkey - ptr > 1) {
- --nextkey;
+ if (nextkey - ptr > 1)
/* Clear trailing ; or / */
- if (*nextkey == ';' || (*nextkey == '/' && *(nextkey - 1) != ':'))
+ if (*--nextkey == ';')
*(*envcpy + (nextkey - ptr)) = '\0';
- }
ptr = *envcpy;
nextkey = ptr;
@@ -2950,10 +2948,6 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, ushort *items)
}
if (*ptr == ';') {
- /* Remove trailing space */
- if (i > 0 && *(ptr - 1) == '/')
- *(ptr - 1) = '\0';
-
*ptr = '\0';
nextkey = ptr + 1;
}
@@ -2996,20 +2990,11 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar max, bool path)
ssize_t len = strlen(home);
ssize_t loclen = strlen(kvarr[r].val);
- if (!buf) {
- buf = (char *)malloc(len + loclen);
- if (!buf) {
- DPRINTF_S(strerror(errno));
- return NULL;
- }
- }
-
- xstrlcpy(buf, home, len + 1);
- xstrlcpy(buf + len, kvarr[r].val + 1, loclen);
- return buf;
+ xstrlcpy(g_buf, home, len + 1);
+ xstrlcpy(g_buf + len, kvarr[r].val + 1, loclen);
}
- return realpath(kvarr[r].val, buf);
+ return realpath(((kvarr[r].val[0] == '~') ? g_buf : kvarr[r].val), buf);
}
}