st-flexipatch

My st-flexipatch configuration
git clone git://git.ethandl.dev/st-flexipatch
Log | Files | Refs | README | LICENSE

commit faac64e392aece75fa3c410e0ce2fb853d7d1e5d
parent 1a8175a33718b87bebbb831231abd8b8219689fb
Author: bakkeby <bakkeby@gmail.com>
Date:   Fri, 11 Mar 2022 09:38:09 +0100

background image: make sure to close the farbfeld file on error

Diffstat:
Mpatch/background_image_x.c | 43+++++++++++++++++--------------------------
1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/patch/background_image_x.c b/patch/background_image_x.c @@ -16,23 +16,20 @@ loadff(const char *filename) FILE *f = fopen(filename, "rb"); if (f == NULL) { - fprintf(stderr, "could not load background image.\n"); - return NULL; + fprintf(stderr, "could not load background image.\n"); + return NULL; } - if (fread(hdr, sizeof(*hdr), LEN(hdr), f) != LEN(hdr)) - if (ferror(f)) { - fprintf(stderr, "fread:"); - return NULL; - } - else { - fprintf(stderr, "fread: Unexpected end of file\n"); - return NULL; - } + if (fread(hdr, sizeof(*hdr), LEN(hdr), f) != LEN(hdr)) { + fprintf(stderr, "fread: %s\n", ferror(f) ? "" : "Unexpected end of file reading header"); + fclose(f); + return NULL; + } if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) { - fprintf(stderr, "Invalid magic value"); - return NULL; + fprintf(stderr, "Invalid magic value\n"); + fclose(f); + return NULL; } w = ntohl(hdr[2]); @@ -40,15 +37,11 @@ loadff(const char *filename) size = w * h; data = malloc(size * sizeof(uint64_t)); - if (fread(data, sizeof(uint64_t), size, f) != size) - if (ferror(f)) { - fprintf(stderr, "fread:"); - return NULL; - } - else { - fprintf(stderr, "fread: Unexpected end of file"); - return NULL; - } + if (fread(data, sizeof(uint64_t), size, f) != size) { + fprintf(stderr, "fread: %s\n", ferror(f) ? "" : "Unexpected end of file reading data"); + fclose(f); + return NULL; + } fclose(f); @@ -91,8 +84,7 @@ bginit() bgimg = XCreatePixmap(xw.dpy, xw.win, bgxi->width, bgxi->height, DefaultDepth(xw.dpy, xw.scr)); #endif // ALPHA_PATCH - XPutImage(xw.dpy, bgimg, dc.gc, bgxi, 0, 0, 0, 0, bgxi->width, - bgxi->height); + XPutImage(xw.dpy, bgimg, dc.gc, bgxi, 0, 0, 0, 0, bgxi->width, bgxi->height); XDestroyImage(bgxi); XSetTile(xw.dpy, xw.bggc, bgimg); XSetFillStyle(xw.dpy, xw.bggc, FillTiled); @@ -101,4 +93,4 @@ bginit() MODBIT(xw.attrs.event_mask, 1, PropertyChangeMask); XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); } -} -\ No newline at end of file +}