From baed6f0a85ade21358cde876c3c044c34749c434 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 19 Jun 2019 19:47:22 +0200 Subject: [PATCH] fixed crash bug caused by division by zero This bug will crash the program when loading a graphics set which uses toon animation step delay values of zero (instead of positive integers as it should be). This bug was introduced around version 4.0.0.0 when adding global animations (treating toon animations as special global animations), which could result in animation delay values of zero even though this was checked and corrected when reading the graphics config file. --- src/anim.c | 3 +++ src/init.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/anim.c b/src/anim.c index 14dccc69..3e2f1222 100644 --- a/src/anim.c +++ b/src/anim.c @@ -242,6 +242,9 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame, { int frame = 0; + if (delay < 1) // delay must be at least 1 + delay = 1; + sync_frame += start_frame * delay; if (mode & ANIM_LOOP) // looping animation diff --git a/src/init.c b/src/init.c index eb18b6da..a022f394 100644 --- a/src/init.c +++ b/src/init.c @@ -1476,7 +1476,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, else g->anim_frames = 1; - if (g->anim_frames == 0) // frames must be at least 1 + if (g->anim_frames < 1) // frames must be at least 1 g->anim_frames = 1; g->anim_frames_per_line = @@ -1484,7 +1484,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line); g->anim_delay = parameter[GFX_ARG_DELAY]; - if (g->anim_delay == 0) // delay must be at least 1 + if (g->anim_delay < 1) // delay must be at least 1 g->anim_delay = 1; g->anim_mode = parameter[GFX_ARG_ANIM_MODE]; @@ -1552,6 +1552,9 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->x = parameter[GFX_ARG_X]; // (may be uninitialized, g->y = parameter[GFX_ARG_Y]; // unlike src_x and src_y) + if (g->step_delay < 1) // delay must be at least 1 + g->step_delay = 1; + // this is only used for drawing font characters g->draw_xoffset = parameter[GFX_ARG_DRAW_XOFFSET]; g->draw_yoffset = parameter[GFX_ARG_DRAW_YOFFSET]; -- 2.34.1