From d2ab4f7f0c3ba4752fe4f810513831898b3ff3e7 Mon Sep 17 00:00:00 2001 From: ckath Date: Sun, 15 Sep 2019 16:28:55 +0200 Subject: [PATCH 1/3] fix cwd length offset this should ensure index will never get overwritten --- fuf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fuf.c b/fuf.c index ebc2197..28eafce 100644 --- a/fuf.c +++ b/fuf.c @@ -386,10 +386,10 @@ refresh_layout() char cwd[PATH_MAX]; /* left corner */ bool cwdok = getcwd(cwd, PATH_MAX); if (cwdok) { - cwd_w = snewwin(1, strlen(cwd) < COLS-strlen(index)-1 ? - strlen(cwd) : COLS-strlen(index)-1, 0, 1); - smvwaddstr(cwd_w, 0, 0, strlen(cwd) < COLS-strlen(index)-1 ? - cwd : cwd + (strlen(cwd)-COLS+strlen(index)+1)); + cwd_w = snewwin(1, strlen(cwd) < COLS-strlen(index)-3 ? + strlen(cwd) : COLS-strlen(index)-3, 0, 1); + smvwaddstr(cwd_w, 0, 0, strlen(cwd) < COLS-strlen(index)-3 ? + cwd : cwd + (strlen(cwd)-COLS+strlen(index)+3)); } else { swattron(dir_w, COLOR_PAIR(COL(COLOR_RED, COLOR_DEFAULT)) | A_BOLD); smvwaddstr(dir_w, 0, 0, "dir not found"); From 8dcef32eef0809801d602f757bb6563a9a661480 Mon Sep 17 00:00:00 2001 From: ckath Date: Sun, 15 Sep 2019 16:50:48 +0200 Subject: [PATCH 2/3] handling of widechars equally bad handling of widechars in strings to compliment how its done in filenames. works 9/10 times. --- fuf.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fuf.c b/fuf.c index 28eafce..7749852 100644 --- a/fuf.c +++ b/fuf.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "ext/colors.h" #include "ext/sncurses.h" #include "ext/sort.h" @@ -384,12 +385,17 @@ refresh_layout() smvwaddstr(preview_w, 0, COLS/2-strlen(index), index); char cwd[PATH_MAX]; /* left corner */ + wchar_t wcwd[PATH_MAX]; bool cwdok = getcwd(cwd, PATH_MAX); + swprintf(wcwd, PATH_MAX, L"%hs", cwd); if (cwdok) { - cwd_w = snewwin(1, strlen(cwd) < COLS-strlen(index)-3 ? - strlen(cwd) : COLS-strlen(index)-3, 0, 1); - smvwaddstr(cwd_w, 0, 0, strlen(cwd) < COLS-strlen(index)-3 ? - cwd : cwd + (strlen(cwd)-COLS+strlen(index)+3)); + int cwd_len = strlen(cwd) > wcslen(wcwd) ? + strlen(cwd)-(strlen(cwd)-wcslen(wcwd))/2 : + strlen(cwd); + cwd_w = snewwin(1, cwd_len < COLS-strlen(index)-3 ? + cwd_len : COLS-strlen(index)-3, 0, 1); + smvwaddstr(cwd_w, 0, 0, cwd_len < COLS-strlen(index)-3 ? + cwd : cwd + (cwd_len-COLS+strlen(index)+3)); } else { swattron(dir_w, COLOR_PAIR(COL(COLOR_RED, COLOR_DEFAULT)) | A_BOLD); smvwaddstr(dir_w, 0, 0, "dir not found"); From 04e57293e14203ecc4aab912eb612be12c9a0d76 Mon Sep 17 00:00:00 2001 From: ckath Date: Sun, 15 Sep 2019 16:53:22 +0200 Subject: [PATCH 3/3] dont do cwd widechar magic unless cwd is valid --- fuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuf.c b/fuf.c index 7749852..610a7ee 100644 --- a/fuf.c +++ b/fuf.c @@ -385,10 +385,10 @@ refresh_layout() smvwaddstr(preview_w, 0, COLS/2-strlen(index), index); char cwd[PATH_MAX]; /* left corner */ - wchar_t wcwd[PATH_MAX]; bool cwdok = getcwd(cwd, PATH_MAX); - swprintf(wcwd, PATH_MAX, L"%hs", cwd); if (cwdok) { + wchar_t wcwd[PATH_MAX]; + swprintf(wcwd, PATH_MAX, L"%hs", cwd); int cwd_len = strlen(cwd) > wcslen(wcwd) ? strlen(cwd)-(strlen(cwd)-wcslen(wcwd))/2 : strlen(cwd);