(svn r10252) -Fix: never overflow when applying exchange rates before drawing the amount of money.
authorrubidium
Thu, 21 Jun 2007 15:57:14 +0000
changeset 7492 6e76d5fd4ca7
parent 7491 8eda96f8600a
child 7493 ab4bd5356d4c
(svn r10252) -Fix: never overflow when applying exchange rates before drawing the amount of money.
src/strings.cpp
--- a/src/strings.cpp	Thu Jun 21 15:48:00 2007 +0000
+++ b/src/strings.cpp	Thu Jun 21 15:57:14 2007 +0000
@@ -340,15 +340,17 @@
 	return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
 }
 
-static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)
+static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money number, bool compact, const char* last)
 {
 	const char* multiplier = "";
 	char buf[40];
 	char* p;
 	int j;
 
-	/* multiply by exchange rate */
-	number *= spec->rate;
+	/* Multiply by exchange rate, but do it safely. */
+	CommandCost cs(number);
+	cs.MultiplyCost(spec->rate);
+	number = cs.GetCost();
 
 	/* convert from negative */
 	if (number < 0) {