cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit 722b5b5a8ad5624adae64d7ee057343501a8c71a
parent ad95a608322bf969248050d14046ed26770040fb
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat,  4 Apr 2026 21:01:04 +0200

fixes

Diffstat:
Mcex.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/cex.c b/cex.c @@ -251,16 +251,19 @@ resize(void) getmaxyx(stdscr, maxy, maxx); + if (parwin.window) delwin(parwin.window); parwin.maxy = maxy-BORDER_SPACE_SIZE; parwin.maxx = maxx/4-BORDER_SPACE_SIZE > 0 ? maxx/4-BORDER_SPACE_SIZE : 1; startx = maxx > BORDER_SPACE_SIZE ? BORDER_SPACE_SIZE : 0; parwin.window = newwin(parwin.maxy, parwin.maxx, BORDER_SPACE_SIZE, startx); + if (curwin.window) delwin(curwin.window); curwin.maxy = maxy-BORDER_SPACE_SIZE; curwin.maxx = maxx/4-BORDER_SPACE_SIZE > 0 ? maxx/4-BORDER_SPACE_SIZE : 1; startx = maxx > curwin.maxx+BORDER_SPACE_SIZE*2 ? curwin.maxx+BORDER_SPACE_SIZE*2 : 0; curwin.window = newwin(curwin.maxy, curwin.maxx, BORDER_SPACE_SIZE, startx); + if (childwin.window) delwin(childwin.window); childwin.maxy = maxy-BORDER_SPACE_SIZE; childwin.maxx = maxx/2-BORDER_SPACE_SIZE > 0 ? maxx/2-BORDER_SPACE_SIZE : 1; startx = maxx > childwin.maxx+BORDER_SPACE_SIZE*2 ? childwin.maxx+BORDER_SPACE_SIZE*2 : 0; @@ -450,7 +453,7 @@ void set_win_files(DirWin *dirwin) { struct dirent *ent; - size_t count = 0; + size_t count = 0, cap = 16; DIR *dir; free_dirwin(dirwin); @@ -468,7 +471,7 @@ set_win_files(DirWin *dirwin) } } - if ((dirwin->winfiles = (WinFile*) malloc(sizeof(WinFile))) == NULL) + if ((dirwin->winfiles = (WinFile*) malloc(cap * sizeof(WinFile))) == NULL) fatal("Fatal: failed to malloc.\n"); while ((ent = readdir(dir)) != NULL) { @@ -476,8 +479,11 @@ set_win_files(DirWin *dirwin) || strcmp(ent->d_name, "..") == 0 || (hide && ent->d_name[0] == '.')) continue; - if ((dirwin->winfiles = (WinFile*) realloc(dirwin->winfiles, (count+1)*(sizeof(WinFile)))) == NULL) - fatal("Fatal: failed to realloc.\n"); + if (count == cap) { + cap *= 2; + if ((dirwin->winfiles = (WinFile*) realloc(dirwin->winfiles, cap * sizeof(WinFile))) == NULL) + fatal("Fatal: failed to realloc.\n"); + } cpstr(dirwin->winfiles[count].d_name, ent->d_name); dirwin->winfiles[count].d_type = ent->d_type; dirwin->winfiles[count].selected = is_selected(dirwin, count);