summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-04-08 19:28:14 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-04-08 19:28:14 +0000
commitbef953a32cd0a8bf3dad5cbbe2798dc3ab57ac5c (patch)
tree9f633a3b6904974299f030d829d5338a3ea7bbc4 /src/linkgraph
parenta9bdb92d19c1104488497f64cddffc71e044c707 (diff)
downloadopenttd-bef953a32cd0a8bf3dad5cbbe2798dc3ab57ac5c.tar.xz
(svn r26448) -Fix [FS#5970]: Avoid division by 0 when scaling flow values.
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/flowmapper.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/linkgraph/flowmapper.cpp b/src/linkgraph/flowmapper.cpp
index 79e0f09f3..3daab4414 100644
--- a/src/linkgraph/flowmapper.cpp
+++ b/src/linkgraph/flowmapper.cpp
@@ -49,8 +49,10 @@ void FlowMapper::Run(LinkGraphJob &job) const
FlowStatMap &flows = node.Flows();
flows.FinalizeLocalConsumption(node.Station());
if (this->scale) {
- /* Scale by time the graph has been running without being compressed. */
- uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression();
+ /* Scale by time the graph has been running without being compressed. Add 1 to avoid
+ * division by 0 if spawn date == last compression date. This matches
+ * LinkGraph::Monthly(). */
+ uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1;
for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) {
i->second.ScaleToMonthly(runtime);
}