diff options
author | rubidium <rubidium@openttd.org> | 2007-09-02 20:41:46 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-09-02 20:41:46 +0000 |
commit | b1effc466eac33997567e2f2e68812afb1c0a7f6 (patch) | |
tree | e63e7fae0c819a5ffcf9150bc1fd58d6048144c9 /src/graph_gui.cpp | |
parent | d396b0c55695414d7ab3d3ddcbe33ecdd4d7f6fa (diff) | |
download | openttd-b1effc466eac33997567e2f2e68812afb1c0a7f6.tar.xz |
(svn r11039) -Fix [FS#1191]: underflow that caused overflows in the performance rating calculation.
Diffstat (limited to 'src/graph_gui.cpp')
-rw-r--r-- | src/graph_gui.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 9599d1fef..7231ec6f3 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1006,13 +1006,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0); /* Calculate the %-bar */ - if (val > needed) { - x = 50; - } else if (val == 0) { - x = 0; - } else { - x = val * 50 / needed; - } + x = clamp(val, 0, needed) * 50 / needed; /* SCORE_LOAN is inversed */ if (val < 0 && i == SCORE_LOAN) x = 0; @@ -1022,7 +1016,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone); /* Calculate the % */ - x = (val <= needed) ? val * 100 / needed : 100; + x = clamp(val, 0, needed) * 100 / needed; /* SCORE_LOAN is inversed */ if (val < 0 && i == SCORE_LOAN) x = 0; |