diff --git a/src/application.c b/src/application.c index 9ad1754..bce633a 100644 --- a/src/application.c +++ b/src/application.c @@ -380,9 +380,8 @@ bool app_init(const char** sources, size_t num) } if (ctx.window.width == SIZE_FULLSCREEN) { ui_toggle_fullscreen(); - } else if (first_image && - (ctx.window.width == SIZE_FROM_IMAGE || - ctx.window.width == SIZE_FROM_PARENT)) { + } else if (ctx.window.width == SIZE_FROM_IMAGE || + ctx.window.width == SIZE_FROM_PARENT) { // fixup window size form the first image const struct pixmap* pm = &first_image->frames[0].pm; ctx.window.width = pm->width; diff --git a/src/config.c b/src/config.c index 71c54f4..10d2f0d 100644 --- a/src/config.c +++ b/src/config.c @@ -116,6 +116,7 @@ static bool load_config(const char* path) // check for section beginning if (*line == '[') { ssize_t len; + char* new_section; ++line; delim = strchr(line, ']'); if (!delim || line + 1 == delim) { @@ -125,8 +126,11 @@ static bool load_config(const char* path) } *delim = 0; len = delim - line + 1; - section = realloc(section, len); - memcpy(section, line, len); + new_section = realloc(section, len); + if (new_section) { + section = new_section; + memcpy(section, line, len); + } continue; } diff --git a/src/formats/jpeg.c b/src/formats/jpeg.c index 9f60de7..b0aadfd 100644 --- a/src/formats/jpeg.c +++ b/src/formats/jpeg.c @@ -76,7 +76,8 @@ enum loader_status decode_jpeg(struct image* ctx, const uint8_t* data, uint32_t* pixel = (uint32_t*)line; for (int x = jpg.output_width - 1; x >= 0; --x) { const uint8_t src = *(line + x); - pixel[x] = (0xff << 24) | src << 16 | src << 8 | src; + pixel[x] = ((argb_t)0xff << 24) | (argb_t)src << 16 | + (argb_t)src << 8 | src; } } @@ -86,7 +87,8 @@ enum loader_status decode_jpeg(struct image* ctx, const uint8_t* data, uint32_t* pixel = (uint32_t*)line; for (int x = jpg.output_width - 1; x >= 0; --x) { const uint8_t* src = line + x * 3; - pixel[x] = (0xff << 24) | src[0] << 16 | src[1] << 8 | src[2]; + pixel[x] = ((argb_t)0xff << 24) | (argb_t)src[0] << 16 | + (argb_t)src[1] << 8 | src[2]; } } #endif // LIBJPEG_TURBO_VERSION diff --git a/src/formats/jxl.c b/src/formats/jxl.c index 4614205..a0e1bf0 100644 --- a/src/formats/jxl.c +++ b/src/formats/jxl.c @@ -15,6 +15,7 @@ enum loader_status decode_jxl(struct image* ctx, const uint8_t* data, JxlBasicInfo info = { 0 }; JxlDecoderStatus status; size_t buffer_sz; + struct image_frame* frames; size_t frame_num = 0; const JxlPixelFormat jxl_format = { .num_channels = 4, // ARBG @@ -72,11 +73,12 @@ enum loader_status decode_jxl(struct image* ctx, const uint8_t* data, frame_num = ctx->num_frames; break; case JXL_DEC_FRAME: - ctx->frames = realloc( - ctx->frames, sizeof(*ctx->frames) * (ctx->num_frames + 1)); - if (!ctx->frames) { + frames = realloc(ctx->frames, + sizeof(*ctx->frames) * (ctx->num_frames + 1)); + if (!frames) { goto fail; } + ctx->frames = frames; if (!pixmap_create(&ctx->frames[frame_num].pm, info.xsize, info.ysize)) { goto fail; diff --git a/src/info.c b/src/info.c index 40d1cb5..79d0700 100644 --- a/src/info.c +++ b/src/info.c @@ -96,6 +96,7 @@ static const struct field_scheme default_gallery_br[] = { #define SET_DEFAULT(m, p, d) \ ctx.scheme[m][p].fields_num = ARRAY_SIZE(d); \ ctx.scheme[m][p].fields = malloc(sizeof(d)); \ + if (ctx.scheme[m][p].fields) \ memcpy(ctx.scheme[m][p].fields, d, sizeof(d)) /** Info scheme: set of fields in one of screen positions. */ diff --git a/src/loader.c b/src/loader.c index cf85b27..6ce11b5 100644 --- a/src/loader.c +++ b/src/loader.c @@ -279,6 +279,8 @@ static enum loader_status image_from_exec(struct image* img, const char* cmd) pid = fork(); if (pid == -1) { + close(pfd[1]); + close(pfd[0]); return ldr_ioerror; } diff --git a/src/pixmap.h b/src/pixmap.h index c063756..c21162e 100644 --- a/src/pixmap.h +++ b/src/pixmap.h @@ -25,10 +25,10 @@ typedef uint32_t argb_t; #define ARGB_GET_B(c) (((c) >> ARGB_B_SHIFT) & 0xff) // create argb_t from channel value -#define ARGB_SET_A(a) (((a) & 0xff) << ARGB_A_SHIFT) -#define ARGB_SET_R(r) (((r) & 0xff) << ARGB_R_SHIFT) -#define ARGB_SET_G(g) (((g) & 0xff) << ARGB_G_SHIFT) -#define ARGB_SET_B(b) (((b) & 0xff) << ARGB_B_SHIFT) +#define ARGB_SET_A(a) (((argb_t)(a) & 0xff) << ARGB_A_SHIFT) +#define ARGB_SET_R(r) (((argb_t)(r) & 0xff) << ARGB_R_SHIFT) +#define ARGB_SET_G(g) (((argb_t)(g) & 0xff) << ARGB_G_SHIFT) +#define ARGB_SET_B(b) (((argb_t)(b) & 0xff) << ARGB_B_SHIFT) // convert ABGR to ARGB #define ABGR_TO_ARGB(c) \ diff --git a/src/str.c b/src/str.c index 2a5e6dc..bb401b7 100644 --- a/src/str.c +++ b/src/str.c @@ -52,6 +52,10 @@ bool str_to_num(const char* text, size_t len, ssize_t* value, int base) char buffer[32]; const char* ptr; + if (!text) { + return false; + } + if (!*text) { return false; } diff --git a/src/viewer.c b/src/viewer.c index 408c033..f875c38 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -257,8 +257,8 @@ static void zoom_image(const char* params) } else if (str_to_num(params, 0, &percent, 0) && percent != 0 && percent > -1000 && percent < 1000) { // zoom in % - const double wnd_half_w = ui_get_width() / 2; - const double wnd_half_h = ui_get_height() / 2; + const double wnd_half_w = (double)ui_get_width() / 2; + const double wnd_half_h = (double)ui_get_height() / 2; const float step = (ctx.scale / 100) * percent; const double center_x = wnd_half_w / ctx.scale - ctx.img_x / ctx.scale; const double center_y = wnd_half_h / ctx.scale - ctx.img_y / ctx.scale;