[Wesnoth-commits] r10000 - /trunk/src/gamestatus.cpp (February 06, 2006 - 02:41)

Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Headers

 

Author: xan
Date: Mon Feb  6 02:40:19 2006
New Revision: 10000

URL: http://svn.gna.org/viewcvs/wesnoth?rev=10000&view=rev
Log:
Division by zero safety.

Modified:
    trunk/src/gamestatus.cpp

Modified: trunk/src/gamestatus.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=10000&r1=9999&r2=10000&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Mon Feb  6 02:40:19 2006
@@ -222,6 +222,11 @@
 {
 	for(std::vector<area_time_of_day>::const_iterator i = areas_.begin(); i != areas_.end(); ++i) {
 		if(i->hexes.count(loc) == 1) {
+			if (i->times.empty()) { // prevent division by zero if no time is available
+				config dummy_cfg;
+				static time_of_day const default_time(dummy_cfg);
+				return default_time;
+			}
 			if(illuminated) {
 				const time_of_day* cur = &i->times[(n_turn-1)%i->times.size()];
 				while(illuminated>0 && cur->lighter) {
@@ -233,7 +238,7 @@
 					illuminated++;
 				}
 				return *cur;
-			} else if(i->times.empty() == false) {
+			} else {
 				return i->times[(n_turn-1)%i->times.size()];
 			}
 		}



Related Mails




Powered by MHonArc, Updated Mon Feb 06 13:00:07 2006