Fix numerical/signed overflow when using high day lengths

Bug reported at day length = 125
This commit is contained in:
Jonathan G Rennison
2017-08-20 20:41:13 +01:00
parent 36a712a579
commit ee169c4455
2 changed files with 4 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ typedef uint16 DateFract; ///< The fraction of a date we're in, i.e. the number
typedef int32 Ticks; ///< The type to store ticks in typedef int32 Ticks; ///< The type to store ticks in
typedef int32 DateTicks; ///< The type to store dates in when tick-precision is required typedef int32 DateTicks; ///< The type to store dates in when tick-precision is required
typedef int64 DateTicksScaled; ///< The type to store dates scaled by the day length factor in when tick-precision is required typedef int64 DateTicksScaled; ///< The type to store dates scaled by the day length factor in when tick-precision is required
typedef int32 Minutes; ///< The type to store minutes in typedef int64 Minutes; ///< The type to store minutes in
typedef int32 Year; ///< Type for the year, note: 0 based, i.e. starts at the year 0. typedef int32 Year; ///< Type for the year, note: 0 based, i.e. starts at the year 0.
typedef uint8 Month; ///< Type for the month, note: 0 based, i.e. 0 = January, 11 = December. typedef uint8 Month; ///< Type for the month, note: 0 based, i.e. 0 = January, 11 = December.

View File

@@ -413,12 +413,12 @@ static char *FormatBytes(char *buff, int64 number, const char *last)
return buff; return buff;
} }
static char *FormatWallClockString(char *buff, DateTicks ticks, const char *last, bool show_date, uint case_index) static char *FormatWallClockString(char *buff, DateTicksScaled ticks, const char *last, bool show_date, uint case_index)
{ {
Minutes minutes = ticks / _settings_client.gui.ticks_per_minute + _settings_client.gui.clock_offset; Minutes minutes = ticks / _settings_client.gui.ticks_per_minute + _settings_client.gui.clock_offset;
char hour[3], minute[3]; char hour[3], minute[3];
seprintf(hour, lastof(hour), "%02i", MINUTES_HOUR(minutes) ); seprintf(hour, lastof(hour), "%02i", (int) MINUTES_HOUR(minutes) );
seprintf(minute, lastof(minute), "%02i", MINUTES_MINUTE(minutes)); seprintf(minute, lastof(minute), "%02i", (int) MINUTES_MINUTE(minutes));
if (show_date) { if (show_date) {
int64 args[3] = { (int64)hour, (int64)minute, (int64)ticks / (DAY_TICKS * _settings_game.economy.day_length_factor) }; int64 args[3] = { (int64)hour, (int64)minute, (int64)ticks / (DAY_TICKS * _settings_game.economy.day_length_factor) };
if (_settings_client.gui.date_with_time == 1) { if (_settings_client.gui.date_with_time == 1) {