summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan G Rennison <j.g.rennison@gmail.com>2018-01-17 02:34:03 +0000
committerPeterN <peter@fuzzle.org>2019-01-24 11:12:06 +0000
commit0240e90169570f2ad2343c3cbbeade7886e599e9 (patch)
treefc0e6670f6898e3adf50145eb0374ad61bfe9934 /src
parentdb924a4681f019a6372f5192693af5aede36d080 (diff)
downloadopenttd-0240e90169570f2ad2343c3cbbeade7886e599e9.tar.xz
Fix: [Blitter] Avoid signed overflow when drawing long lines
Diffstat (limited to 'src')
-rw-r--r--src/blitter/common.hpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/blitter/common.hpp b/src/blitter/common.hpp
index 0e255ca9a..9019dd359 100644
--- a/src/blitter/common.hpp
+++ b/src/blitter/common.hpp
@@ -50,11 +50,11 @@ void Blitter::DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, in
/* compute frac_diff = width * sqrt(dx*dx + dy*dy)
* Start interval:
* max(dx, dy) <= sqrt(dx*dx + dy*dy) <= sqrt(2) * max(dx, dy) <= 3/2 * max(dx, dy) */
- int frac_sq = width * width * (dx * dx + dy * dy);
+ int64 frac_sq = ((int64) width) * ((int64) width) * (((int64) dx) * ((int64) dx) + ((int64) dy) * ((int64) dy));
int frac_max = 3 * frac_diff / 2;
while (frac_diff < frac_max) {
int frac_test = (frac_diff + frac_max) / 2;
- if (frac_test * frac_test < frac_sq) {
+ if (((int64) frac_test) * ((int64) frac_test) < frac_sq) {
frac_diff = frac_test + 1;
} else {
frac_max = frac_test - 1;