From 01f3cf2e4778940a82001e48cfeec767841f52c4 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 28 Jan 2023 10:27:40 +0000 Subject: use assertions instead of ignoring bogus arguments (#406) instead of silently ignoring bogus arguments (i.e programming errors), which can make debugging harder, it's better to assert them so that they get caught faster in debug builds. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/406 Reviewed-by: explosion-mental --- thumbs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'thumbs.c') diff --git a/thumbs.c b/thumbs.c index c9e97c4..038b501 100644 --- a/thumbs.c +++ b/thumbs.c @@ -21,6 +21,7 @@ #define INCLUDE_THUMBS_CONFIG #include "config.h" +#include #include #include #include @@ -40,8 +41,7 @@ static char* tns_cache_filepath(const char *filepath) size_t len; char *cfile = NULL; - if (*filepath != '/') - return NULL; + assert(*filepath == '/' && "filepath should be result of realpath(3)"); if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) { /* don't cache images inside the cache directory! */ @@ -355,9 +355,7 @@ void tns_unload(tns_t *tns, int n) { thumb_t *t; - if (n < 0 || n >= *tns->cnt) - return; - + assert(n >= 0 && n < *tns->cnt); t = &tns->thumbs[n]; if (t->im != NULL) { @@ -371,9 +369,7 @@ static void tns_check_view(tns_t *tns, bool scrolled) { int r; - if (tns == NULL) - return; - + assert(tns != NULL); tns->first -= tns->first % tns->cols; r = *tns->sel % tns->cols; -- cgit v1.2.3-54-g00ecf