Removed overcautious parameter checks

This commit is contained in:
Bert Münnich 2015-10-28 20:59:48 +01:00
parent a3838c1984
commit e0e96977b3
6 changed files with 11 additions and 147 deletions

View File

@ -1,4 +1,4 @@
VERSION := git-20150819 VERSION := git-20151028
PREFIX := /usr/local PREFIX := /usr/local
MANPREFIX := $(PREFIX)/share/man MANPREFIX := $(PREFIX)/share/man

55
image.c
View File

@ -51,9 +51,6 @@ void img_init(img_t *img, win_t *win)
zoom_min = zoom_levels[0] / 100.0; zoom_min = zoom_levels[0] / 100.0;
zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0;
if (img == NULL || win == NULL)
return;
imlib_context_set_display(win->env.dpy); imlib_context_set_display(win->env.dpy);
imlib_context_set_visual(win->env.vis); imlib_context_set_visual(win->env.vis);
imlib_context_set_colormap(win->env.cmap); imlib_context_set_colormap(win->env.cmap);
@ -300,9 +297,6 @@ bool img_load(img_t *img, const fileinfo_t *file)
{ {
const char *fmt; const char *fmt;
if (img == NULL || file == NULL || file->name == NULL || file->path == NULL)
return false;
if (access(file->path, R_OK) < 0 || if (access(file->path, R_OK) < 0 ||
(img->im = imlib_load_image(file->path)) == NULL) (img->im = imlib_load_image(file->path)) == NULL)
{ {
@ -336,9 +330,6 @@ void img_close(img_t *img, bool decache)
{ {
int i; int i;
if (img == NULL)
return;
if (img->multi.cnt > 0) { if (img->multi.cnt > 0) {
for (i = 0; i < img->multi.cnt; i++) { for (i = 0; i < img->multi.cnt; i++) {
imlib_context_set_image(img->multi.frames[i].im); imlib_context_set_image(img->multi.frames[i].im);
@ -362,9 +353,6 @@ void img_check_pan(img_t *img, bool moved)
int ox, oy; int ox, oy;
float w, h; float w, h;
if (img == NULL || img->im == NULL || img->win == NULL)
return;
win = img->win; win = img->win;
w = img->w * img->zoom; w = img->w * img->zoom;
h = img->h * img->zoom; h = img->h * img->zoom;
@ -392,8 +380,6 @@ bool img_fit(img_t *img)
{ {
float z, zmax, zw, zh; float z, zmax, zw, zh;
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
if (img->scalemode == SCALE_ZOOM) if (img->scalemode == SCALE_ZOOM)
return false; return false;
@ -433,9 +419,6 @@ void img_render(img_t *img)
Imlib_Image bg; Imlib_Image bg;
unsigned long c; unsigned long c;
if (img == NULL || img->im == NULL || img->win == NULL)
return;
win = img->win; win = img->win;
img_fit(img); img_fit(img);
@ -521,9 +504,6 @@ bool img_fit_win(img_t *img, scalemode_t sm)
{ {
float oz; float oz;
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
oz = img->zoom; oz = img->zoom;
img->scalemode = sm; img->scalemode = sm;
@ -539,9 +519,6 @@ bool img_fit_win(img_t *img, scalemode_t sm)
bool img_zoom(img_t *img, float z) bool img_zoom(img_t *img, float z)
{ {
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
z = MAX(z, zoom_min); z = MAX(z, zoom_min);
z = MIN(z, zoom_max); z = MIN(z, zoom_max);
@ -564,9 +541,6 @@ bool img_zoom_in(img_t *img)
int i; int i;
float z; float z;
if (img == NULL || img->im == NULL)
return false;
for (i = 1; i < ARRLEN(zoom_levels); i++) { for (i = 1; i < ARRLEN(zoom_levels); i++) {
z = zoom_levels[i] / 100.0; z = zoom_levels[i] / 100.0;
if (zoomdiff(z, img->zoom) > 0) if (zoomdiff(z, img->zoom) > 0)
@ -580,9 +554,6 @@ bool img_zoom_out(img_t *img)
int i; int i;
float z; float z;
if (img == NULL || img->im == NULL)
return false;
for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) { for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
z = zoom_levels[i] / 100.0; z = zoom_levels[i] / 100.0;
if (zoomdiff(z, img->zoom) < 0) if (zoomdiff(z, img->zoom) < 0)
@ -595,9 +566,6 @@ bool img_move(img_t *img, float dx, float dy)
{ {
float ox, oy; float ox, oy;
if (img == NULL || img->im == NULL)
return false;
ox = img->x; ox = img->x;
oy = img->y; oy = img->y;
@ -622,9 +590,6 @@ bool img_pan(img_t *img, direction_t dir, int d)
*/ */
float x, y; float x, y;
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
if (d > 0) { if (d > 0) {
x = y = MAX(1, (float) d * img->zoom); x = y = MAX(1, (float) d * img->zoom);
} else { } else {
@ -649,9 +614,6 @@ bool img_pan_edge(img_t *img, direction_t dir)
{ {
int ox, oy; int ox, oy;
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
ox = img->x; ox = img->x;
oy = img->y; oy = img->y;
@ -678,9 +640,6 @@ void img_rotate(img_t *img, degree_t d)
{ {
int i, ox, oy, tmp; int i, ox, oy, tmp;
if (img == NULL || img->im == NULL || img->win == NULL)
return;
imlib_context_set_image(img->im); imlib_context_set_image(img->im);
imlib_image_orientate(d); imlib_image_orientate(d);
@ -716,7 +675,7 @@ void img_flip(img_t *img, flipdir_t d)
d = (d & (FLIP_HORIZONTAL | FLIP_VERTICAL)) - 1; d = (d & (FLIP_HORIZONTAL | FLIP_VERTICAL)) - 1;
if (img == NULL || img->im == NULL || d < 0 || d >= ARRLEN(imlib_flip_op)) if (d < 0 || d >= ARRLEN(imlib_flip_op))
return; return;
imlib_context_set_image(img->im); imlib_context_set_image(img->im);
@ -733,9 +692,6 @@ void img_flip(img_t *img, flipdir_t d)
void img_toggle_antialias(img_t *img) void img_toggle_antialias(img_t *img)
{ {
if (img == NULL || img->im == NULL)
return;
img->aa = !img->aa; img->aa = !img->aa;
imlib_context_set_image(img->im); imlib_context_set_image(img->im);
imlib_context_set_anti_alias(img->aa); imlib_context_set_anti_alias(img->aa);
@ -751,9 +707,6 @@ bool img_change_gamma(img_t *img, int d)
int gamma; int gamma;
double range; double range;
if (img == NULL)
return false;
if (d == 0) if (d == 0)
gamma = 0; gamma = 0;
else else
@ -775,8 +728,6 @@ bool img_change_gamma(img_t *img, int d)
bool img_frame_goto(img_t *img, int n) bool img_frame_goto(img_t *img, int n)
{ {
if (img == NULL || img->im == NULL)
return false;
if (n < 0 || n >= img->multi.cnt || n == img->multi.sel) if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
return false; return false;
@ -794,7 +745,7 @@ bool img_frame_goto(img_t *img, int n)
bool img_frame_navigate(img_t *img, int d) bool img_frame_navigate(img_t *img, int d)
{ {
if (img == NULL|| img->im == NULL || img->multi.cnt == 0 || d == 0) if (img->multi.cnt == 0 || d == 0)
return false; return false;
d += img->multi.sel; d += img->multi.sel;
@ -808,7 +759,7 @@ bool img_frame_navigate(img_t *img, int d)
bool img_frame_animate(img_t *img) bool img_frame_animate(img_t *img)
{ {
if (img == NULL || img->im == NULL || img->multi.cnt == 0) if (img->multi.cnt == 0)
return false; return false;
if (img->multi.sel + 1 >= img->multi.cnt) if (img->multi.sel + 1 >= img->multi.cnt)

11
main.c
View File

@ -117,7 +117,7 @@ void check_add_file(char *filename, bool given)
{ {
const char *bn; const char *bn;
if (filename == NULL || *filename == '\0') if (*filename == '\0')
return; return;
if (access(filename, R_OK) < 0) { if (access(filename, R_OK) < 0) {
@ -323,7 +323,8 @@ void load_image(int new)
if (new < 0 || new >= filecnt) if (new < 0 || new >= filecnt)
return; return;
win_set_cursor(&win, CURSOR_WATCH); if (win.xwin != None)
win_set_cursor(&win, CURSOR_WATCH);
reset_timeout(slideshow); reset_timeout(slideshow);
if (new != current) if (new != current)
@ -590,9 +591,6 @@ void on_keypress(XKeyEvent *kev)
char key; char key;
bool dirty = false; bool dirty = false;
if (kev == NULL)
return;
if (kev->state & ShiftMask) { if (kev->state & ShiftMask) {
kev->state &= ~ShiftMask; kev->state &= ~ShiftMask;
XLookupString(kev, &key, 1, &shksym, NULL); XLookupString(kev, &key, 1, &shksym, NULL);
@ -633,9 +631,6 @@ void on_buttonpress(XButtonEvent *bev)
bool dirty = false; bool dirty = false;
static Time firstclick; static Time firstclick;
if (bev == NULL)
return;
if (mode == MODE_IMAGE) { if (mode == MODE_IMAGE) {
win_set_cursor(&win, CURSOR_ARROW); win_set_cursor(&win, CURSOR_ARROW);
set_timeout(reset_cursor, TO_CURSOR_HIDE, true); set_timeout(reset_cursor, TO_CURSOR_HIDE, true);

View File

@ -43,7 +43,7 @@ char* tns_cache_filepath(const char *filepath)
size_t len; size_t len;
char *cfile = NULL; char *cfile = NULL;
if (cache_dir == NULL || filepath == NULL || *filepath != '/') if (*filepath != '/')
return NULL; return NULL;
if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) { if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
@ -61,8 +61,6 @@ Imlib_Image tns_cache_load(const char *filepath, bool *outdated)
struct stat cstats, fstats; struct stat cstats, fstats;
Imlib_Image im = NULL; Imlib_Image im = NULL;
if (filepath == NULL)
return NULL;
if (stat(filepath, &fstats) < 0) if (stat(filepath, &fstats) < 0)
return NULL; return NULL;
@ -85,8 +83,6 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force)
struct utimbuf times; struct utimbuf times;
Imlib_Load_Error err = 0; Imlib_Load_Error err = 0;
if (im == NULL || filepath == NULL)
return;
if (stat(filepath, &fstats) < 0) if (stat(filepath, &fstats) < 0)
return; return;
@ -126,9 +122,6 @@ void tns_clean_cache(tns_t *tns)
char *cfile, *filename, *tpos; char *cfile, *filename, *tpos;
r_dir_t dir; r_dir_t dir;
if (cache_dir == NULL)
return;
if (r_opendir(&dir, cache_dir) < 0) { if (r_opendir(&dir, cache_dir) < 0) {
warn("could not open thumbnail cache directory: %s", cache_dir); warn("could not open thumbnail cache directory: %s", cache_dir);
return; return;
@ -162,9 +155,6 @@ void tns_init(tns_t *tns, fileinfo_t *files, const int *cnt, int *sel,
int len; int len;
const char *homedir, *dsuffix = ""; const char *homedir, *dsuffix = "";
if (tns == NULL)
return;
if (cnt != NULL && *cnt > 0) { if (cnt != NULL && *cnt > 0) {
tns->thumbs = (thumb_t*) s_malloc(*cnt * sizeof(thumb_t)); tns->thumbs = (thumb_t*) s_malloc(*cnt * sizeof(thumb_t));
memset(tns->thumbs, 0, *cnt * sizeof(thumb_t)); memset(tns->thumbs, 0, *cnt * sizeof(thumb_t));
@ -200,9 +190,6 @@ void tns_free(tns_t *tns)
{ {
int i; int i;
if (tns == NULL)
return;
if (tns->thumbs != NULL) { if (tns->thumbs != NULL) {
for (i = 0; i < *tns->cnt; i++) { for (i = 0; i < *tns->cnt; i++) {
if (tns->thumbs[i].im != NULL) { if (tns->thumbs[i].im != NULL) {
@ -253,8 +240,6 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
fileinfo_t *file; fileinfo_t *file;
Imlib_Image im = NULL; Imlib_Image im = NULL;
if (tns == NULL || tns->thumbs == NULL)
return false;
if (n < 0 || n >= *tns->cnt) if (n < 0 || n >= *tns->cnt)
return false; return false;
file = &tns->files[n]; file = &tns->files[n];
@ -386,8 +371,6 @@ void tns_unload(tns_t *tns, int n)
{ {
thumb_t *t; thumb_t *t;
if (tns == NULL || tns->thumbs == NULL)
return;
if (n < 0 || n >= *tns->cnt) if (n < 0 || n >= *tns->cnt)
return; return;
@ -434,8 +417,6 @@ void tns_render(tns_t *tns)
win_t *win; win_t *win;
int i, cnt, r, x, y; int i, cnt, r, x, y;
if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
return;
if (!tns->dirty) if (!tns->dirty)
return; return;
@ -495,9 +476,6 @@ void tns_render(tns_t *tns)
void tns_mark(tns_t *tns, int n, bool mark) void tns_mark(tns_t *tns, int n, bool mark)
{ {
if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
return;
if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) { if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
win_t *win = tns->win; win_t *win = tns->win;
thumb_t *t = &tns->thumbs[n]; thumb_t *t = &tns->thumbs[n];
@ -519,9 +497,6 @@ void tns_mark(tns_t *tns, int n, bool mark)
void tns_highlight(tns_t *tns, int n, bool hl) void tns_highlight(tns_t *tns, int n, bool hl)
{ {
if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
return;
if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) { if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
win_t *win = tns->win; win_t *win = tns->win;
thumb_t *t = &tns->thumbs[n]; thumb_t *t = &tns->thumbs[n];
@ -545,9 +520,6 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt)
{ {
int old, max; int old, max;
if (tns == NULL || tns->thumbs == NULL)
return false;
old = *tns->sel; old = *tns->sel;
cnt = cnt > 1 ? cnt : 1; cnt = cnt > 1 ? cnt : 1;
@ -581,9 +553,6 @@ bool tns_scroll(tns_t *tns, direction_t dir, bool screen)
{ {
int d, max, old; int d, max, old;
if (tns == NULL)
return false;
old = tns->first; old = tns->first;
d = tns->cols * (screen ? tns->rows : 1); d = tns->cols * (screen ? tns->rows : 1);
@ -607,9 +576,6 @@ bool tns_zoom(tns_t *tns, int d)
{ {
int i, oldzl; int i, oldzl;
if (tns == NULL || tns->thumbs == NULL)
return false;
oldzl = tns->zl; oldzl = tns->zl;
tns->zl += -(d < 0) + (d > 0); tns->zl += -(d < 0) + (d > 0);
tns->zl = MAX(tns->zl, 0); tns->zl = MAX(tns->zl, 0);
@ -631,8 +597,6 @@ int tns_translate(tns_t *tns, int x, int y)
{ {
int n; int n;
if (tns == NULL || tns->thumbs == NULL)
return -1;
if (x < tns->x || y < tns->y) if (x < tns->x || y < tns->y)
return -1; return -1;

15
util.c
View File

@ -103,9 +103,6 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream)
size_t len; size_t len;
char *s; char *s;
if (stream == NULL || feof(stream) || ferror(stream))
return -1;
if (*buf == NULL || *n == 0) { if (*buf == NULL || *n == 0) {
*n = BUF_SIZE; *n = BUF_SIZE;
*buf = (char*) s_malloc(*n); *buf = (char*) s_malloc(*n);
@ -148,7 +145,7 @@ char* absolute_path(const char *filename)
char *dir, *dirname = NULL, *path = NULL, *s; char *dir, *dirname = NULL, *path = NULL, *s;
char *cwd = NULL, *twd = NULL; char *cwd = NULL, *twd = NULL;
if (filename == NULL || *filename == '\0' || *filename == '/') if (*filename == '\0' || *filename == '/')
return NULL; return NULL;
len = FNAME_LEN; len = FNAME_LEN;
@ -211,7 +208,7 @@ end:
int r_opendir(r_dir_t *rdir, const char *dirname) int r_opendir(r_dir_t *rdir, const char *dirname)
{ {
if (rdir == NULL || dirname == NULL || *dirname == '\0') if (*dirname == '\0')
return -1; return -1;
if ((rdir->dir = opendir(dirname)) == NULL) { if ((rdir->dir = opendir(dirname)) == NULL) {
@ -234,9 +231,6 @@ int r_closedir(r_dir_t *rdir)
{ {
int ret = 0; int ret = 0;
if (rdir == NULL)
return -1;
if (rdir->stack != NULL) { if (rdir->stack != NULL) {
while (rdir->stlen > 0) while (rdir->stlen > 0)
free(rdir->stack[--rdir->stlen]); free(rdir->stack[--rdir->stlen]);
@ -264,9 +258,6 @@ char* r_readdir(r_dir_t *rdir)
struct dirent *dentry; struct dirent *dentry;
struct stat fstats; struct stat fstats;
if (rdir == NULL || rdir->dir == NULL || rdir->name == NULL)
return NULL;
while (true) { while (true) {
if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) { if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) {
if (dentry->d_name[0] == '.') if (dentry->d_name[0] == '.')
@ -316,7 +307,7 @@ int r_mkdir(const char *path)
struct stat stats; struct stat stats;
int err = 0; int err = 0;
if (path == NULL || *path == '\0') if (*path == '\0')
return -1; return -1;
if (stat(path, &stats) == 0) if (stat(path, &stats) == 0)

View File

@ -94,8 +94,6 @@ unsigned long win_alloc_color(win_t *win, const char *name)
{ {
XColor col; XColor col;
if (win == NULL)
return 0UL;
if (XAllocNamedColor(win->env.dpy, if (XAllocNamedColor(win->env.dpy,
DefaultColormap(win->env.dpy, win->env.scr), DefaultColormap(win->env.dpy, win->env.scr),
name, &col, &col) == 0) name, &col, &col) == 0)
@ -142,9 +140,6 @@ void win_init(win_t *win)
{ {
win_env_t *e; win_env_t *e;
if (win == NULL)
return;
memset(win, 0, sizeof(win_t)); memset(win, 0, sizeof(win_t));
e = &win->env; e = &win->env;
@ -199,9 +194,6 @@ void win_open(win_t *win)
XSizeHints sizehints; XSizeHints sizehints;
Bool fullscreen = options->fullscreen && fs_support; Bool fullscreen = options->fullscreen && fs_support;
if (win == NULL)
return;
e = &win->env; e = &win->env;
sizehints.flags = PWinGravity; sizehints.flags = PWinGravity;
@ -317,9 +309,6 @@ void win_open(win_t *win)
void win_close(win_t *win) void win_close(win_t *win)
{ {
if (win == NULL || win->xwin == None)
return;
XFreeCursor(win->env.dpy, carrow); XFreeCursor(win->env.dpy, carrow);
XFreeCursor(win->env.dpy, cnone); XFreeCursor(win->env.dpy, cnone);
XFreeCursor(win->env.dpy, chand); XFreeCursor(win->env.dpy, chand);
@ -335,9 +324,6 @@ bool win_configure(win_t *win, XConfigureEvent *c)
{ {
bool changed; bool changed;
if (win == NULL || c == NULL)
return false;
changed = win->w != c->width || win->h + win->bar.h != c->height; changed = win->w != c->width || win->h + win->bar.h != c->height;
win->x = c->x; win->x = c->x;
@ -354,9 +340,6 @@ void win_toggle_fullscreen(win_t *win)
XEvent ev; XEvent ev;
XClientMessageEvent *cm; XClientMessageEvent *cm;
if (win == NULL || win->xwin == None)
return;
if (!fs_support) { if (!fs_support) {
if (!fs_warned) { if (!fs_warned) {
warn("window manager does not support fullscreen"); warn("window manager does not support fullscreen");
@ -383,9 +366,6 @@ void win_toggle_fullscreen(win_t *win)
void win_toggle_bar(win_t *win) void win_toggle_bar(win_t *win)
{ {
if (win == NULL || win->xwin == None)
return;
if (win->bar.h != 0) { if (win->bar.h != 0) {
win->h += win->bar.h; win->h += win->bar.h;
win->bar.h = 0; win->bar.h = 0;
@ -399,9 +379,6 @@ void win_clear(win_t *win)
{ {
win_env_t *e; win_env_t *e;
if (win == NULL || win->xwin == None)
return;
e = &win->env; e = &win->env;
if (win->w > win->buf.w || win->h + win->bar.h > win->buf.h) { if (win->w > win->buf.w || win->h + win->bar.h > win->buf.h) {
@ -423,8 +400,6 @@ void win_draw_bar(win_t *win)
win_env_t *e; win_env_t *e;
win_bar_t *l, *r; win_bar_t *l, *r;
if (win == NULL || win->xwin == None)
return;
if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL) if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL)
return; return;
@ -473,9 +448,6 @@ void win_draw_bar(win_t *win)
void win_draw(win_t *win) void win_draw(win_t *win)
{ {
if (win == NULL || win->xwin == None)
return;
if (win->bar.h > 0) if (win->bar.h > 0)
win_draw_bar(win); win_draw_bar(win);
@ -489,9 +461,6 @@ void win_draw_rect(win_t *win, int x, int y, int w, int h, bool fill, int lw,
{ {
XGCValues gcval; XGCValues gcval;
if (win == NULL || win->buf.pm == None)
return;
gcval.line_width = lw; gcval.line_width = lw;
gcval.foreground = col; gcval.foreground = col;
XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval); XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval);
@ -517,9 +486,6 @@ int win_textwidth(const char *text, unsigned int len, bool with_padding)
void win_set_title(win_t *win, const char *title) void win_set_title(win_t *win, const char *title)
{ {
if (win == NULL || win->xwin == None)
return;
if (title == NULL) if (title == NULL)
title = "sxiv"; title = "sxiv";
@ -536,9 +502,6 @@ void win_set_title(win_t *win, const char *title)
void win_set_cursor(win_t *win, cursor_t cursor) void win_set_cursor(win_t *win, cursor_t cursor)
{ {
if (win == NULL || win->xwin == None)
return;
switch (cursor) { switch (cursor) {
case CURSOR_NONE: case CURSOR_NONE:
XDefineCursor(win->env.dpy, win->xwin, cnone); XDefineCursor(win->env.dpy, win->xwin, cnone);