mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
Fix: use reference and array indexing to prevent suspicious pointer scaling
This commit is contained in:
parent
fbd0f5ad7d
commit
496ec1f012
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user