From 864d2352c29e3f5e9e10eacd8222f2feb94610a8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 15 Jul 2023 19:25:45 +0100 Subject: [PATCH] Fix: Integer overflow in LinkGraphOverlay::ShowTooltip for long links In particular when fully zoomed in This could result in tooltips not being shown at all, or being shown when not appropriate --- src/linkgraph/linkgraph_gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index fd1b3eaee9..2742c51370 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -369,8 +369,8 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond) /* Check the distance from the cursor to the line defined by the two stations. */ Point ptb = this->GetStationMiddle(Station::Get(j->first)); - float dist = std::abs((ptb.x - pta.x) * (pta.y - pt.y) - (pta.x - pt.x) * (ptb.y - pta.y)) / - std::sqrt((ptb.x - pta.x) * (ptb.x - pta.x) + (ptb.y - pta.y) * (ptb.y - pta.y)); + float dist = std::abs((int64)(ptb.x - pta.x) * (int64)(pta.y - pt.y) - (int64)(pta.x - pt.x) * (int64)(ptb.y - pta.y)) / + std::sqrt((int64)(ptb.x - pta.x) * (int64)(ptb.x - pta.x) + (int64)(ptb.y - pta.y) * (int64)(ptb.y - pta.y)); const auto &link = j->second; if (dist <= 4 && link.Usage() > 0 && pt.x + 2 >= std::min(pta.x, ptb.x) &&