Fix a potential out-of-bounds array access in RGBGFX

This was caught by ASAN for pokered's gfx/battle/minimize.png.
This commit is contained in:
Rangi
2021-05-01 22:33:54 -04:00
parent dcb8c69661
commit 04788e15af

View File

@@ -224,7 +224,11 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb,
if (!tile)
err(1, "%s: Failed to allocate memory for tile",
__func__);
for (i = 0; i < tile_size; i++) {
/*
* If the input image doesn't fill the last tile,
* `gb_i` will reach `gb_size`.
*/
for (i = 0; i < tile_size && gb_i < gb_size; i++) {
tile[i] = gb->data[gb_i];
gb_i++;
}