Krolyxon
Commit 127abbe

Branches

Refs →

nsxiv127abbe

fix crash when zooming out on small images (#178)

When rendering images, destination image width and height may become
zero due to float-to-int conversion after zoom calculation, later
crashing when creating an image using those dimensions. This sets
a minimum of 1 to both variables.

Closes #82
Author
mamg22
Date
2021-11-30 19:52 -0400
Committer
GitHub · 2021-12-01 05:52 +0600
Parent
3bc7082
Commit
127abbea770e1fff660b0ffd10ab58bcb46bf0af

+2 −2

1 file changed

  1. M image.c +2 −2
M image.c View
@@ -602,7 +602,7 @@ void img_render(img_t *img)
602602 sx = 0;
603603 sw = img->w;
604604 dx = img->x;
605− dw = img->w * img->zoom;
605+ dw = MAX(img->w * img->zoom, 1);
606606 }
607607 if (img->y <= 0) {
608608 sy = -img->y / img->zoom + 0.5;
@@ -613,7 +613,7 @@ void img_render(img_t *img)
613613 sy = 0;
614614 sh = img->h;
615615 dy = img->y;
616− dh = img->h * img->zoom;
616+ dh = MAX(img->h * img->zoom, 1);
617617 }
618618
619619 win_clear(win);