lel

Fork of Hiltjo's Farbfeld image viewer. (It was just for fun, not much use)
Log | Files | Refs | README | LICENSE

commit eff5c89f690c55745e345cb81382fe8e3ee39606
parent 60e3e2ebae4f13828b0493193c9f7f4999c75fd7
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Mon, 19 Apr 2021 16:18:23 -0700

Fix image navigation

Previously img.index could something invalid like -1.

Diffstat:
Mlel.c | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lel.c b/lel.c @@ -213,11 +213,12 @@ getbin(char *s) static void deleteimg(void) { - ff_close(&img); imgs[img.index] = NULL; - if (--nimgs < 1) + if (--nimgs <= 0) exit(0); nextimg(); + if (imgs[img.index] == NULL) + previmg(); } static void @@ -262,9 +263,9 @@ reloadimg(void) static void nextimg(void) { - while (img.index < lastimg && imgs[++img.index] == NULL) - ; - if (imgs[img.index] == NULL) { + if (img.index + 1 > lastimg) + return; + if (imgs[++img.index] == NULL) { nextimg(); } else { ff_close(&img); @@ -275,10 +276,10 @@ nextimg(void) static void previmg(void) { - while (img.index > 0 && imgs[--img.index] == NULL) - ; - if (imgs[img.index] == NULL) { - nextimg(); + if (img.index - 1 < 0) + return; + if (imgs[--img.index] == NULL) { + previmg(); } else { ff_close(&img); reloadimg();