mirror of
https://github.com/jarun/nnn.git
synced 2025-03-01 20:39:20 +00:00
Catch NULL from malloc() (#438)
* Catch NULL from malloc() * Tidy up errors * Make indentaion look pretty in git
This commit is contained in:
parent
b1c9f4ed45
commit
4930f34c3f
1 changed files with 19 additions and 2 deletions
21
src/nnn.c
21
src/nnn.c
|
@ -1675,7 +1675,14 @@ static void get_archive_cmd(char *cmd, 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)
|
||||||
{
|
{
|
||||||
char *buf = (char *)malloc(CMD_LEN_MAX * sizeof(char));
|
/* The 70 comes from the string below */
|
||||||
|
char *buf = (char *)malloc((70 + strlen(cmd) + strlen(archive)
|
||||||
|
+ strlen(curpath) + strlen(g_selpath)) * sizeof(char));
|
||||||
|
if (!buf) {
|
||||||
|
DPRINTF_S(strerror(errno));
|
||||||
|
printwarn(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buf, CMD_LEN_MAX,
|
snprintf(buf, CMD_LEN_MAX,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -2628,8 +2635,13 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar max, bool path)
|
||||||
ssize_t len = strlen(home);
|
ssize_t len = strlen(home);
|
||||||
ssize_t loclen = strlen(kvarr[r].val);
|
ssize_t loclen = strlen(kvarr[r].val);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf) {
|
||||||
buf = (char *)malloc(len + loclen);
|
buf = (char *)malloc(len + loclen);
|
||||||
|
if (!buf) {
|
||||||
|
DPRINTF_S(strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
xstrlcpy(buf, home, len + 1);
|
xstrlcpy(buf, home, len + 1);
|
||||||
xstrlcpy(buf + len, kvarr[r].val + 1, loclen);
|
xstrlcpy(buf + len, kvarr[r].val + 1, loclen);
|
||||||
|
@ -5841,6 +5853,11 @@ static bool setup_config(void)
|
||||||
if (!cfg.picker) {
|
if (!cfg.picker) {
|
||||||
/* Length of "/.config/nnn/.selection" */
|
/* Length of "/.config/nnn/.selection" */
|
||||||
g_selpath = (char *)malloc(len + 3);
|
g_selpath = (char *)malloc(len + 3);
|
||||||
|
if (!g_selpath) {
|
||||||
|
xerror();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
r = xstrlcpy(g_selpath, cfgdir, len + 3);
|
r = xstrlcpy(g_selpath, cfgdir, len + 3);
|
||||||
xstrlcpy(g_selpath + r - 1, "/.selection", 12);
|
xstrlcpy(g_selpath + r - 1, "/.selection", 12);
|
||||||
DPRINTF_S(g_selpath);
|
DPRINTF_S(g_selpath);
|
||||||
|
|
Loading…
Add table
Reference in a new issue