cex

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

commit 68c0c815592e004b9e898a6767bb0e18321d5a07
parent acee0332f26386775c4680f924bb3c4b8b5597b3
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat,  4 Jul 2026 10:30:10 +0200

improvements

Diffstat:
Mcex.c | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/cex.c b/cex.c @@ -122,7 +122,7 @@ static char *replace_home(char *buf, const char *path); static mode_t get_st_mode(DirWin *dirwin, size_t index); static DirWin curwin, parwin, childwin; -static char *userhome, *username, *editor, **selected, searchq[SEARCHLEN]; +static char *userhome, *username, *editor, **selected, searchq[SEARCHLEN+1]; static int maxy, maxx; static size_t selc, searchc; static bool print_bot, hide = DEFAULT_HIDE, searchcs = DEFAULT_SEARCH_CASE_SENS; @@ -570,8 +570,8 @@ print_win(DirWin *dirwin) if (dirwin->holdupdate) return; - size_t cplen, size = dirwin->maxx; - char *subs, name[size+1], sbuf[size+1]; + size_t cplen, len, width = dirwin->maxx > 1 ? (size_t) dirwin->maxx-1 : 0; + char *subs, name[sizeof(dirwin->winfiles[0].d_name)+1], sbuf[SEARCHLEN+1]; int sindex, y = 0, x = 1; werase(dirwin->window); @@ -596,8 +596,6 @@ print_win(DirWin *dirwin) curbase = curwin.path; while (!dirwin->usehighlight) { for (int i = 0; i < dirwin->filecount; ++i) { - memcpy(name, dirwin->winfiles[i].d_name, size); - name[size] = '\0'; if (strcmp(curbase, dirwin->winfiles[i].d_name) == 0) { dirwin->usehighlight = TRUE; dirwin->highlight = i; @@ -614,8 +612,10 @@ print_win(DirWin *dirwin) mvwaddch(dirwin->window, y, x-1, '|'); wattroff(dirwin->window, COLOR_PAIR(MARK_SELECTED_COLOR)); } - memcpy(name, dirwin->winfiles[i].d_name, size); - name[size-1] = '\0'; + len = MIN(strnlen(dirwin->winfiles[i].d_name, + sizeof(dirwin->winfiles[i].d_name)), width); + memcpy(name, dirwin->winfiles[i].d_name, len); + name[len] = '\0'; if (dirwin->usehighlight && dirwin->highlight == i) { wattron(dirwin->window, A_REVERSE); mvwaddstr(dirwin->window, y, x, name); @@ -1149,6 +1149,7 @@ search(void) default: if (searchc < SEARCHLEN) { searchq[(searchc)++] = c; + searchq[searchc] = '\0'; move(y, ++x); } break; @@ -1779,8 +1780,7 @@ clear_selected(void) void clear_search(void) { - for (int i = 0; i < SEARCHLEN; i++) - searchq[i] = '\0'; + searchq[0] = '\0'; searchc = 0; }