From 496ec1f012e0f085c09f666ddfb55828101dbe42 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 2 Jan 2023 23:17:24 +0100 Subject: [PATCH] Fix: use reference and array indexing to prevent suspicious pointer scaling --- src/company_gui.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index bf43af43d4..965d0c804b 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -227,7 +227,7 @@ static void DrawPrice(Money amount, int left, int right, int top, TextColour col * Draw a category of expenses/revenues in the year column. * @return The income sum of the category. */ -static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, const Money(*tbl)[EXPENSES_END]) +static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, const Money(&tbl)[EXPENSES_END]) { int y = start_y; ExpensesType et; @@ -235,7 +235,7 @@ static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, co for (uint i = 0; i < list.length; i++) { et = list.et[i]; - Money cost = (*tbl)[et]; + Money cost = tbl[et]; sum += cost; if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK); y += FONT_HEIGHT_NORMAL; @@ -255,10 +255,10 @@ static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, co * Draw a column with prices. * @param r Available space for drawing. * @param year Year being drawn. - * @param tbl Pointer to table of amounts for \a year. + * @param tbl Reference to table of amounts for \a year. * @note The environment must provide padding at the left and right of \a r. */ -static void DrawYearColumn(const Rect &r, int year, const Money (*tbl)[EXPENSES_END]) +static void DrawYearColumn(const Rect &r, int year, const Money (&tbl)[EXPENSES_END]) { int y = r.top; Money sum; @@ -435,7 +435,7 @@ struct CompanyFinancesWindow : Window { int age = std::min(_cur_year - c->inaugurated_year, 2); int wid_offset = widget - WID_CF_EXPS_PRICE1; if (wid_offset <= age) { - DrawYearColumn(r, _cur_year - (age - wid_offset), c->yearly_expenses + (age - wid_offset)); + DrawYearColumn(r, _cur_year - (age - wid_offset), c->yearly_expenses[age - wid_offset]); } break; }