Cap the maximum indexes into image
authorBill Lash <william.lash@gmail.com>
Wed, 2 Oct 2019 23:42:24 +0000 (18:42 -0500)
committerBill Lash <william.lash@gmail.com>
Sat, 5 Oct 2019 22:43:28 +0000 (17:43 -0500)
Make sure not to index past the right and/or bottom edge of the
image while scaling.

src/sdl/sf_video.c

index 135ef1df6670b508c80a64884e3885bad47e1c0d..c056929ec1939e12f1898f8da6879f0981a66e0d 100644 (file)
@@ -601,8 +601,12 @@ void os_draw_picture(int picture, int y, int x)
 
                for (yy = 0; yy < eh * m_gfxScale_h; yy++) {
                        int ys = ceil(yy / m_gfxScale_h);
+                       if (ys >= pic->height)
+                           ys = pic->height - 1;
                        for (xx = 0; xx < ew * m_gfxScale_w; xx++) {
                                int xs = ceil(xx / m_gfxScale_w);
+                               if (xs >= pic->width)
+                                   xs = pic->width - 1;
                                int index = pic->pixels[ys * pic->width + xs];
                                if (index != pic->transparentcolor)
                                        sf_wpixel(x + xx, y + yy,