← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1573545-dismantlesite-crash into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1573545-dismantlesite-crash into lp:widelands.

Commit message:
Protect against division by 0 when drawing dismantlesite.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1573545 in widelands: "dismantlesite.cc: Arithmetic exception crash"
  https://bugs.launchpad.net/widelands/+bug/1573545

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1573545-dismantlesite-crash/+merge/292701

Constructionsites already have this fix.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1573545-dismantlesite-crash into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc	2016-04-01 15:54:39 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc	2016-04-23 09:01:56 +0000
@@ -239,7 +239,7 @@
 
 	// Draw the partially dismantled building
 	static_assert(0 <= DISMANTLESITE_STEP_TIME, "assert(0 <= DISMANTLESITE_STEP_TIME) failed.");
-	uint32_t total_time = DISMANTLESITE_STEP_TIME * work_steps_;
+	const uint32_t total_time = DISMANTLESITE_STEP_TIME * work_steps_;
 	uint32_t completed_time = DISMANTLESITE_STEP_TIME * work_completed_;
 
 	if (working_)
@@ -255,7 +255,7 @@
 	const uint16_t w = anim.width();
 	const uint16_t h = anim.height();
 
-	uint32_t lines = h * completed_time / total_time;
+	const uint32_t lines = total_time ? h * completed_time / total_time : 0;
 
 	dst.blit_animation(pos, anim_idx, tanim, player_color, Rect(Point(0, lines), w, h - lines));
 


Follow ups