Krolyxon
Commit e0e9697

Branches

Refs →

nsxive0e9697

Removed overcautious parameter checks

Author
Bert Münnich
Date
2015-10-28 20:59 +0100
Committer
Bert Münnich · 2015-10-28 21:01 +0100
Parent
a3838c1
Commit
e0e96977b348772cac67282a6591d6c58eeaa927

+11 −147

6 files changed

  1. M Makefile +1 −1
  2. M image.c +3 −52
  3. M main.c +3 −8
  4. M thumbs.c +1 −37
  5. M util.c +3 −12
  6. M window.c +0 −37
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION := git-20150819
1+VERSION := git-20151028
22
33 PREFIX := /usr/local
44 MANPREFIX := $(PREFIX)/share/man
M image.c View
@@ -51,9 +51,6 @@ void img_init(img_t *img, win_t *win)
5151 zoom_min = zoom_levels[0] / 100.0;
5252 zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0;
5353
54− if (img == NULL || win == NULL)
55− return;
56−
5754 imlib_context_set_display(win->env.dpy);
5855 imlib_context_set_visual(win->env.vis);
5956 imlib_context_set_colormap(win->env.cmap);
@@ -300,9 +297,6 @@ bool img_load(img_t *img, const fileinfo_t *file)
300297 {
301298 const char *fmt;
302299
303− if (img == NULL || file == NULL || file->name == NULL || file->path == NULL)
304− return false;
305−
306300 if (access(file->path, R_OK) < 0 ||
307301 (img->im = imlib_load_image(file->path)) == NULL)
308302 {
@@ -336,9 +330,6 @@ void img_close(img_t *img, bool decache)
336330 {
337331 int i;
338332
339− if (img == NULL)
340− return;
341−
342333 if (img->multi.cnt > 0) {
343334 for (i = 0; i < img->multi.cnt; i++) {
344335 imlib_context_set_image(img->multi.frames[i].im);
@@ -362,9 +353,6 @@ void img_check_pan(img_t *img, bool moved)
362353 int ox, oy;
363354 float w, h;
364355
365− if (img == NULL || img->im == NULL || img->win == NULL)
366− return;
367−
368356 win = img->win;
369357 w = img->w * img->zoom;
370358 h = img->h * img->zoom;
@@ -392,8 +380,6 @@ bool img_fit(img_t *img)
392380 {
393381 float z, zmax, zw, zh;
394382
395− if (img == NULL || img->im == NULL || img->win == NULL)
396− return false;
397383 if (img->scalemode == SCALE_ZOOM)
398384 return false;
399385
@@ -433,9 +419,6 @@ void img_render(img_t *img)
433419 Imlib_Image bg;
434420 unsigned long c;
435421
436− if (img == NULL || img->im == NULL || img->win == NULL)
437− return;
438−
439422 win = img->win;
440423 img_fit(img);
441424
@@ -521,9 +504,6 @@ bool img_fit_win(img_t *img, scalemode_t sm)
521504 {
522505 float oz;
523506
524− if (img == NULL || img->im == NULL || img->win == NULL)
525− return false;
526−
527507 oz = img->zoom;
528508 img->scalemode = sm;
529509
@@ -539,9 +519,6 @@ bool img_fit_win(img_t *img, scalemode_t sm)
539519
540520 bool img_zoom(img_t *img, float z)
541521 {
542− if (img == NULL || img->im == NULL || img->win == NULL)
543− return false;
544−
545522 z = MAX(z, zoom_min);
546523 z = MIN(z, zoom_max);
547524
@@ -564,9 +541,6 @@ bool img_zoom_in(img_t *img)
564541 int i;
565542 float z;
566543
567− if (img == NULL || img->im == NULL)
568− return false;
569−
570544 for (i = 1; i < ARRLEN(zoom_levels); i++) {
571545 z = zoom_levels[i] / 100.0;
572546 if (zoomdiff(z, img->zoom) > 0)
@@ -580,9 +554,6 @@ bool img_zoom_out(img_t *img)
580554 int i;
581555 float z;
582556
583− if (img == NULL || img->im == NULL)
584− return false;
585−
586557 for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
587558 z = zoom_levels[i] / 100.0;
588559 if (zoomdiff(z, img->zoom) < 0)
@@ -595,9 +566,6 @@ bool img_move(img_t *img, float dx, float dy)
595566 {
596567 float ox, oy;
597568
598− if (img == NULL || img->im == NULL)
599− return false;
600−
601569 ox = img->x;
602570 oy = img->y;
603571
@@ -622,9 +590,6 @@ bool img_pan(img_t *img, direction_t dir, int d)
622590 */
623591 float x, y;
624592
625− if (img == NULL || img->im == NULL || img->win == NULL)
626− return false;
627−
628593 if (d > 0) {
629594 x = y = MAX(1, (float) d * img->zoom);
630595 } else {
@@ -649,9 +614,6 @@ bool img_pan_edge(img_t *img, direction_t dir)
649614 {
650615 int ox, oy;
651616
652− if (img == NULL || img->im == NULL || img->win == NULL)
653− return false;
654−
655617 ox = img->x;
656618 oy = img->y;
657619
@@ -678,9 +640,6 @@ void img_rotate(img_t *img, degree_t d)
678640 {
679641 int i, ox, oy, tmp;
680642
681− if (img == NULL || img->im == NULL || img->win == NULL)
682− return;
683−
684643 imlib_context_set_image(img->im);
685644 imlib_image_orientate(d);
686645
@@ -716,7 +675,7 @@ void img_flip(img_t *img, flipdir_t d)
716675
717676 d = (d & (FLIP_HORIZONTAL | FLIP_VERTICAL)) - 1;
718677
719− if (img == NULL || img->im == NULL || d < 0 || d >= ARRLEN(imlib_flip_op))
678+ if (d < 0 || d >= ARRLEN(imlib_flip_op))
720679 return;
721680
722681 imlib_context_set_image(img->im);
@@ -733,9 +692,6 @@ void img_flip(img_t *img, flipdir_t d)
733692
734693 void img_toggle_antialias(img_t *img)
735694 {
736− if (img == NULL || img->im == NULL)
737− return;
738−
739695 img->aa = !img->aa;
740696 imlib_context_set_image(img->im);
741697 imlib_context_set_anti_alias(img->aa);
@@ -751,9 +707,6 @@ bool img_change_gamma(img_t *img, int d)
751707 int gamma;
752708 double range;
753709
754− if (img == NULL)
755− return false;
756−
757710 if (d == 0)
758711 gamma = 0;
759712 else
@@ -775,8 +728,6 @@ bool img_change_gamma(img_t *img, int d)
775728
776729 bool img_frame_goto(img_t *img, int n)
777730 {
778− if (img == NULL || img->im == NULL)
779− return false;
780731 if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
781732 return false;
782733
@@ -794,7 +745,7 @@ bool img_frame_goto(img_t *img, int n)
794745
795746 bool img_frame_navigate(img_t *img, int d)
796747 {
797− if (img == NULL|| img->im == NULL || img->multi.cnt == 0 || d == 0)
748+ if (img->multi.cnt == 0 || d == 0)
798749 return false;
799750
800751 d += img->multi.sel;
@@ -808,7 +759,7 @@ bool img_frame_navigate(img_t *img, int d)
808759
809760 bool img_frame_animate(img_t *img)
810761 {
811− if (img == NULL || img->im == NULL || img->multi.cnt == 0)
762+ if (img->multi.cnt == 0)
812763 return false;
813764
814765 if (img->multi.sel + 1 >= img->multi.cnt)
M main.c View
@@ -117,7 +117,7 @@ void check_add_file(char *filename, bool given)
117117 {
118118 const char *bn;
119119
120− if (filename == NULL || *filename == '\0')
120+ if (*filename == '\0')
121121 return;
122122
123123 if (access(filename, R_OK) < 0) {
@@ -323,7 +323,8 @@ void load_image(int new)
323323 if (new < 0 || new >= filecnt)
324324 return;
325325
326− win_set_cursor(&win, CURSOR_WATCH);
326+ if (win.xwin != None)
327+ win_set_cursor(&win, CURSOR_WATCH);
327328 reset_timeout(slideshow);
328329
329330 if (new != current)
@@ -590,9 +591,6 @@ void on_keypress(XKeyEvent *kev)
590591 char key;
591592 bool dirty = false;
592593
593− if (kev == NULL)
594− return;
595−
596594 if (kev->state & ShiftMask) {
597595 kev->state &= ~ShiftMask;
598596 XLookupString(kev, &key, 1, &shksym, NULL);
@@ -633,9 +631,6 @@ void on_buttonpress(XButtonEvent *bev)
633631 bool dirty = false;
634632 static Time firstclick;
635633
636− if (bev == NULL)
637− return;
638−
639634 if (mode == MODE_IMAGE) {
640635 win_set_cursor(&win, CURSOR_ARROW);
641636 set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
M thumbs.c View
@@ -43,7 +43,7 @@ char* tns_cache_filepath(const char *filepath)
4343 size_t len;
4444 char *cfile = NULL;
4545
46− if (cache_dir == NULL || filepath == NULL || *filepath != '/')
46+ if (*filepath != '/')
4747 return NULL;
4848
4949 if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
@@ -61,8 +61,6 @@ Imlib_Image tns_cache_load(const char *filepath, bool *outdated)
6161 struct stat cstats, fstats;
6262 Imlib_Image im = NULL;
6363
64− if (filepath == NULL)
65− return NULL;
6664 if (stat(filepath, &fstats) < 0)
6765 return NULL;
6866
@@ -85,8 +83,6 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force)
8583 struct utimbuf times;
8684 Imlib_Load_Error err = 0;
8785
88− if (im == NULL || filepath == NULL)
89− return;
9086 if (stat(filepath, &fstats) < 0)
9187 return;
9288
@@ -126,9 +122,6 @@ void tns_clean_cache(tns_t *tns)
126122 char *cfile, *filename, *tpos;
127123 r_dir_t dir;
128124
129− if (cache_dir == NULL)
130− return;
131−
132125 if (r_opendir(&dir, cache_dir) < 0) {
133126 warn("could not open thumbnail cache directory: %s", cache_dir);
134127 return;
@@ -162,9 +155,6 @@ void tns_init(tns_t *tns, fileinfo_t *files, const int *cnt, int *sel,
162155 int len;
163156 const char *homedir, *dsuffix = "";
164157
165− if (tns == NULL)
166− return;
167−
168158 if (cnt != NULL && *cnt > 0) {
169159 tns->thumbs = (thumb_t*) s_malloc(*cnt * sizeof(thumb_t));
170160 memset(tns->thumbs, 0, *cnt * sizeof(thumb_t));
@@ -200,9 +190,6 @@ void tns_free(tns_t *tns)
200190 {
201191 int i;
202192
203− if (tns == NULL)
204− return;
205−
206193 if (tns->thumbs != NULL) {
207194 for (i = 0; i < *tns->cnt; i++) {
208195 if (tns->thumbs[i].im != NULL) {
@@ -253,8 +240,6 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
253240 fileinfo_t *file;
254241 Imlib_Image im = NULL;
255242
256− if (tns == NULL || tns->thumbs == NULL)
257− return false;
258243 if (n < 0 || n >= *tns->cnt)
259244 return false;
260245 file = &tns->files[n];
@@ -386,8 +371,6 @@ void tns_unload(tns_t *tns, int n)
386371 {
387372 thumb_t *t;
388373
389− if (tns == NULL || tns->thumbs == NULL)
390− return;
391374 if (n < 0 || n >= *tns->cnt)
392375 return;
393376
@@ -434,8 +417,6 @@ void tns_render(tns_t *tns)
434417 win_t *win;
435418 int i, cnt, r, x, y;
436419
437− if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
438− return;
439420 if (!tns->dirty)
440421 return;
441422
@@ -495,9 +476,6 @@ void tns_render(tns_t *tns)
495476
496477 void tns_mark(tns_t *tns, int n, bool mark)
497478 {
498− if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
499− return;
500−
501479 if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
502480 win_t *win = tns->win;
503481 thumb_t *t = &tns->thumbs[n];
@@ -519,9 +497,6 @@ void tns_mark(tns_t *tns, int n, bool mark)
519497
520498 void tns_highlight(tns_t *tns, int n, bool hl)
521499 {
522− if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
523− return;
524−
525500 if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
526501 win_t *win = tns->win;
527502 thumb_t *t = &tns->thumbs[n];
@@ -545,9 +520,6 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt)
545520 {
546521 int old, max;
547522
548− if (tns == NULL || tns->thumbs == NULL)
549− return false;
550−
551523 old = *tns->sel;
552524 cnt = cnt > 1 ? cnt : 1;
553525
@@ -581,9 +553,6 @@ bool tns_scroll(tns_t *tns, direction_t dir, bool screen)
581553 {
582554 int d, max, old;
583555
584− if (tns == NULL)
585− return false;
586−
587556 old = tns->first;
588557 d = tns->cols * (screen ? tns->rows : 1);
589558
@@ -607,9 +576,6 @@ bool tns_zoom(tns_t *tns, int d)
607576 {
608577 int i, oldzl;
609578
610− if (tns == NULL || tns->thumbs == NULL)
611− return false;
612−
613579 oldzl = tns->zl;
614580 tns->zl += -(d < 0) + (d > 0);
615581 tns->zl = MAX(tns->zl, 0);
@@ -631,8 +597,6 @@ int tns_translate(tns_t *tns, int x, int y)
631597 {
632598 int n;
633599
634− if (tns == NULL || tns->thumbs == NULL)
635− return -1;
636600 if (x < tns->x || y < tns->y)
637601 return -1;
638602
M util.c View
@@ -103,9 +103,6 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream)
103103 size_t len;
104104 char *s;
105105
106− if (stream == NULL || feof(stream) || ferror(stream))
107− return -1;
108−
109106 if (*buf == NULL || *n == 0) {
110107 *n = BUF_SIZE;
111108 *buf = (char*) s_malloc(*n);
@@ -148,7 +145,7 @@ char* absolute_path(const char *filename)
148145 char *dir, *dirname = NULL, *path = NULL, *s;
149146 char *cwd = NULL, *twd = NULL;
150147
151− if (filename == NULL || *filename == '\0' || *filename == '/')
148+ if (*filename == '\0' || *filename == '/')
152149 return NULL;
153150
154151 len = FNAME_LEN;
@@ -211,7 +208,7 @@ end:
211208
212209 int r_opendir(r_dir_t *rdir, const char *dirname)
213210 {
214− if (rdir == NULL || dirname == NULL || *dirname == '\0')
211+ if (*dirname == '\0')
215212 return -1;
216213
217214 if ((rdir->dir = opendir(dirname)) == NULL) {
@@ -234,9 +231,6 @@ int r_closedir(r_dir_t *rdir)
234231 {
235232 int ret = 0;
236233
237− if (rdir == NULL)
238− return -1;
239−
240234 if (rdir->stack != NULL) {
241235 while (rdir->stlen > 0)
242236 free(rdir->stack[--rdir->stlen]);
@@ -264,9 +258,6 @@ char* r_readdir(r_dir_t *rdir)
264258 struct dirent *dentry;
265259 struct stat fstats;
266260
267− if (rdir == NULL || rdir->dir == NULL || rdir->name == NULL)
268− return NULL;
269−
270261 while (true) {
271262 if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) {
272263 if (dentry->d_name[0] == '.')
@@ -316,7 +307,7 @@ int r_mkdir(const char *path)
316307 struct stat stats;
317308 int err = 0;
318309
319− if (path == NULL || *path == '\0')
310+ if (*path == '\0')
320311 return -1;
321312
322313 if (stat(path, &stats) == 0)
M window.c View
@@ -94,8 +94,6 @@ unsigned long win_alloc_color(win_t *win, const char *name)
9494 {
9595 XColor col;
9696
97− if (win == NULL)
98− return 0UL;
9997 if (XAllocNamedColor(win->env.dpy,
10098 DefaultColormap(win->env.dpy, win->env.scr),
10199 name, &col, &col) == 0)
@@ -142,9 +140,6 @@ void win_init(win_t *win)
142140 {
143141 win_env_t *e;
144142
145− if (win == NULL)
146− return;
147−
148143 memset(win, 0, sizeof(win_t));
149144
150145 e = &win->env;
@@ -199,9 +194,6 @@ void win_open(win_t *win)
199194 XSizeHints sizehints;
200195 Bool fullscreen = options->fullscreen && fs_support;
201196
202− if (win == NULL)
203− return;
204−
205197 e = &win->env;
206198
207199 sizehints.flags = PWinGravity;
@@ -317,9 +309,6 @@ void win_open(win_t *win)
317309
318310 void win_close(win_t *win)
319311 {
320− if (win == NULL || win->xwin == None)
321− return;
322−
323312 XFreeCursor(win->env.dpy, carrow);
324313 XFreeCursor(win->env.dpy, cnone);
325314 XFreeCursor(win->env.dpy, chand);
@@ -335,9 +324,6 @@ bool win_configure(win_t *win, XConfigureEvent *c)
335324 {
336325 bool changed;
337326
338− if (win == NULL || c == NULL)
339− return false;
340−
341327 changed = win->w != c->width || win->h + win->bar.h != c->height;
342328
343329 win->x = c->x;
@@ -354,9 +340,6 @@ void win_toggle_fullscreen(win_t *win)
354340 XEvent ev;
355341 XClientMessageEvent *cm;
356342
357− if (win == NULL || win->xwin == None)
358− return;
359−
360343 if (!fs_support) {
361344 if (!fs_warned) {
362345 warn("window manager does not support fullscreen");
@@ -383,9 +366,6 @@ void win_toggle_fullscreen(win_t *win)
383366
384367 void win_toggle_bar(win_t *win)
385368 {
386− if (win == NULL || win->xwin == None)
387− return;
388−
389369 if (win->bar.h != 0) {
390370 win->h += win->bar.h;
391371 win->bar.h = 0;
@@ -399,9 +379,6 @@ void win_clear(win_t *win)
399379 {
400380 win_env_t *e;
401381
402− if (win == NULL || win->xwin == None)
403− return;
404−
405382 e = &win->env;
406383
407384 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)
423400 win_env_t *e;
424401 win_bar_t *l, *r;
425402
426− if (win == NULL || win->xwin == None)
427− return;
428403 if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL)
429404 return;
430405
@@ -473,9 +448,6 @@ void win_draw_bar(win_t *win)
473448
474449 void win_draw(win_t *win)
475450 {
476− if (win == NULL || win->xwin == None)
477− return;
478−
479451 if (win->bar.h > 0)
480452 win_draw_bar(win);
481453
@@ -489,9 +461,6 @@ void win_draw_rect(win_t *win, int x, int y, int w, int h, bool fill, int lw,
489461 {
490462 XGCValues gcval;
491463
492− if (win == NULL || win->buf.pm == None)
493− return;
494−
495464 gcval.line_width = lw;
496465 gcval.foreground = col;
497466 XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval);
@@ -517,9 +486,6 @@ int win_textwidth(const char *text, unsigned int len, bool with_padding)
517486
518487 void win_set_title(win_t *win, const char *title)
519488 {
520− if (win == NULL || win->xwin == None)
521− return;
522−
523489 if (title == NULL)
524490 title = "sxiv";
525491
@@ -536,9 +502,6 @@ void win_set_title(win_t *win, const char *title)
536502
537503 void win_set_cursor(win_t *win, cursor_t cursor)
538504 {
539− if (win == NULL || win->xwin == None)
540− return;
541−
542505 switch (cursor) {
543506 case CURSOR_NONE:
544507 XDefineCursor(win->env.dpy, win->xwin, cnone);