mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Change string copies to use strlcpy(3)
This commit is contained in:
parent
1734a96745
commit
b6c43f66a9
1
Makefile
1
Makefile
|
@ -1,6 +1,7 @@
|
||||||
#CPPFLAGS += -DDEBUG
|
#CPPFLAGS += -DDEBUG
|
||||||
#CFLAGS += -g
|
#CFLAGS += -g
|
||||||
LDLIBS = -lncursesw
|
LDLIBS = -lncursesw
|
||||||
|
#LDLIBS += -lbsd
|
||||||
BIN = noice
|
BIN = noice
|
||||||
|
|
||||||
all: $(BIN)
|
all: $(BIN)
|
||||||
|
|
10
noice.c
10
noice.c
|
@ -13,6 +13,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef LINUX
|
||||||
|
#include <bsd/string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define DEBUG_FD 8
|
#define DEBUG_FD 8
|
||||||
#define DPRINTF_D(x) dprintf(DEBUG_FD, #x "=%d\n", x)
|
#define DPRINTF_D(x) dprintf(DEBUG_FD, #x "=%d\n", x)
|
||||||
|
@ -280,13 +284,13 @@ redraw:
|
||||||
|
|
||||||
/* No text wrapping in cwd line */
|
/* No text wrapping in cwd line */
|
||||||
cwd = malloc(COLS * sizeof(char));
|
cwd = malloc(COLS * sizeof(char));
|
||||||
strncpy(cwd, path, COLS);
|
strlcpy(cwd, path, COLS * sizeof(char));
|
||||||
cwd[COLS - strlen(CWD) - 1] = '\0';
|
cwd[COLS - strlen(CWD) - 1] = '\0';
|
||||||
|
|
||||||
/* No text wrapping in entries */
|
/* No text wrapping in entries */
|
||||||
tmpents = malloc(n * sizeof(*tmpents));
|
tmpents = malloc(n * sizeof(*tmpents));
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
strncpy(tmpents[i].name, dents[i]->d_name,
|
strlcpy(tmpents[i].name, dents[i]->d_name,
|
||||||
sizeof(tmpents[i].name));
|
sizeof(tmpents[i].name));
|
||||||
tmpents[i].name[COLS - strlen(CURSR) - 1] = '\0';
|
tmpents[i].name[COLS - strlen(CURSR) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -335,7 +339,7 @@ nochange:
|
||||||
|
|
||||||
dir = dirname(path);
|
dir = dirname(path);
|
||||||
tmp = malloc(strlen(dir) + 1);
|
tmp = malloc(strlen(dir) + 1);
|
||||||
strncpy(tmp, dir, strlen(dir) + 1);
|
strlcpy(tmp, dir, strlen(dir) + 1);
|
||||||
free(path);
|
free(path);
|
||||||
path = tmp;
|
path = tmp;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Reference in a new issue