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 <explosion-mental@noreply.codeberg.org>
This commit is contained in:
parent
6ffc64a04e
commit
01f3cf2e47
12
thumbs.c
12
thumbs.c
@ -21,6 +21,7 @@
|
|||||||
#define INCLUDE_THUMBS_CONFIG
|
#define INCLUDE_THUMBS_CONFIG
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -40,8 +41,7 @@ static char* tns_cache_filepath(const char *filepath)
|
|||||||
size_t len;
|
size_t len;
|
||||||
char *cfile = NULL;
|
char *cfile = NULL;
|
||||||
|
|
||||||
if (*filepath != '/')
|
assert(*filepath == '/' && "filepath should be result of realpath(3)");
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
|
if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
|
||||||
/* don't cache images inside the cache directory! */
|
/* don't cache images inside the cache directory! */
|
||||||
@ -355,9 +355,7 @@ void tns_unload(tns_t *tns, int n)
|
|||||||
{
|
{
|
||||||
thumb_t *t;
|
thumb_t *t;
|
||||||
|
|
||||||
if (n < 0 || n >= *tns->cnt)
|
assert(n >= 0 && n < *tns->cnt);
|
||||||
return;
|
|
||||||
|
|
||||||
t = &tns->thumbs[n];
|
t = &tns->thumbs[n];
|
||||||
|
|
||||||
if (t->im != NULL) {
|
if (t->im != NULL) {
|
||||||
@ -371,9 +369,7 @@ static void tns_check_view(tns_t *tns, bool scrolled)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (tns == NULL)
|
assert(tns != NULL);
|
||||||
return;
|
|
||||||
|
|
||||||
tns->first -= tns->first % tns->cols;
|
tns->first -= tns->first % tns->cols;
|
||||||
r = *tns->sel % tns->cols;
|
r = *tns->sel % tns->cols;
|
||||||
|
|
||||||
|
3
util.c
3
util.c
@ -226,8 +226,7 @@ void construct_argv(char **argv, unsigned int len, ...)
|
|||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < len; ++i)
|
||||||
argv[i] = va_arg(args, char *);
|
argv[i] = va_arg(args, char *);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if (argv[len-1] != NULL)
|
assert(argv[len-1] == NULL && "argv should be NULL terminated");
|
||||||
error(EXIT_FAILURE, 0, "argv not NULL terminated");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx)
|
static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx)
|
||||||
|
7
window.c
7
window.c
@ -22,6 +22,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "icon/data.h"
|
#include "icon/data.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -450,10 +451,10 @@ static void win_draw_bar(win_t *win)
|
|||||||
win_bar_t *l, *r;
|
win_bar_t *l, *r;
|
||||||
XftDraw *d;
|
XftDraw *d;
|
||||||
|
|
||||||
if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
e = &win->env;
|
e = &win->env;
|
||||||
|
l = &win->bar.l;
|
||||||
|
r = &win->bar.r;
|
||||||
|
assert(l->buf != NULL && r->buf != NULL);
|
||||||
y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD;
|
y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD;
|
||||||
w = win->w - 2*H_TEXT_PAD;
|
w = win->w - 2*H_TEXT_PAD;
|
||||||
d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
|
d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
|
||||||
|
Loading…
Reference in New Issue
Block a user