summaryrefslogtreecommitdiff
path: root/src/command.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-20 14:51:09 +0000
committerrubidium <rubidium@openttd.org>2007-10-20 14:51:09 +0000
commit8212088c03c0a0af451f734391699e5dab8d8608 (patch)
tree28fbe813d418b83e119aa615200f98b20ba520c8 /src/command.cpp
parent54369cba0f9d1cda2d40752eb337d153b3b6775f (diff)
downloadopenttd-8212088c03c0a0af451f734391699e5dab8d8608.tar.xz
(svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
Diffstat (limited to 'src/command.cpp')
-rw-r--r--src/command.cpp16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 4370f9b19..e2133fe4f 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -677,25 +677,13 @@ CommandCost CommandCost::AddCost(CommandCost ret)
CommandCost CommandCost::AddCost(Money cost)
{
- /* Overflow protection */
- if (cost < 0 && (this->cost + cost) > this->cost) {
- this->cost = INT64_MIN;
- } else if (cost > 0 && (this->cost + cost) < this->cost) {
- this->cost = INT64_MAX;
- } else {
- this->cost += cost;
- }
+ this->cost += cost;
return *this;
}
CommandCost CommandCost::MultiplyCost(int factor)
{
- /* Overflow protection */
- if (factor != 0 && (INT64_MAX / myabs(factor)) < myabs(this->cost)) {
- this->cost = (this->cost < 0 == factor < 0) ? INT64_MAX : INT64_MIN;
- } else {
- this->cost *= factor;
- }
+ this->cost *= factor;
return *this;
}