sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 414299e97579feb30513c6c284480c6f146b55f5
parent 464dd5d6fb21a74c68d35821fd279a7fa6fd3af3
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sun,  6 Jan 2019 00:22:58 +0100

build-page: fix dirent reuse with readdir loop in menu_panel

Diffstat:
Mbuild-page.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/build-page.c b/build-page.c @@ -13,7 +13,7 @@ #include <unistd.h> #define CONVERTER "smu","-n" -#define LEN(x) (sizeof(x) / sizeof *(x)) +#define LEN(x) (sizeof(x) / sizeof(x[0])) #define TITLE_MAX 1024 #define TITLE_DEFAULT "suckless.org" #define DIR_MAX 1024 @@ -87,6 +87,17 @@ die(char *fmt, ...) exit(1); } +char * +xstrdup(const char *s) +{ + char *p = strdup(s); + + if (!p) + die_perror("strdup"); + + return p; +} + int stat_isdir(const char *f) { @@ -226,12 +237,12 @@ menu_panel(char *domain, char *page, char *this, int depth) d_len = 0; while (d_len + 1 < LEN(d_list) && (de = readdir(dp))) - d_list[d_len++] = de->d_name; + d_list[d_len++] = xstrdup(de->d_name); d_list[d_len] = NULL; qsort(d_list, d_len, sizeof *d_list, qsort_strcmp); - for (d = d_list; *d != NULL; ++d) { + for (d = d_list; *d != NULL; free(*d++)) { if (**d == '.') continue; subdir(newdir, sizeof newdir, this, *d);