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
+2 −2
1 file changed
- M image.c +2 −2
| @@ -602,7 +602,7 @@ void img_render(img_t *img) | |||
| 602 | 602 | sx = 0; | |
| 603 | 603 | sw = img->w; | |
| 604 | 604 | dx = img->x; | |
| 605 | − | dw = img->w * img->zoom; | |
| 605 | + | dw = MAX(img->w * img->zoom, 1); | |
| 606 | 606 | } | |
| 607 | 607 | if (img->y <= 0) { | |
| 608 | 608 | sy = -img->y / img->zoom + 0.5; | |
| @@ -613,7 +613,7 @@ void img_render(img_t *img) | |||
| 613 | 613 | sy = 0; | |
| 614 | 614 | sh = img->h; | |
| 615 | 615 | dy = img->y; | |
| 616 | − | dh = img->h * img->zoom; | |
| 616 | + | dh = MAX(img->h * img->zoom, 1); | |
| 617 | 617 | } | |
| 618 | 618 | ||
| 619 | 619 | win_clear(win); | |