Changeset - r26724:7d792683319b
[Not reviewed]
master
0 1 0
Rubidium - 20 months ago 2023-01-02 22:17:24
rubidium@openttd.org
Fix: use reference and array indexing to prevent suspicious pointer scaling
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -224,21 +224,21 @@ static void DrawPrice(Money amount, int 
 
}
 

	
 
/**
 
 * 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;
 
	Money sum = 0;
 

	
 
	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;
 
	}
 

	
 
	/* Draw the total at the bottom of the category. */
 
@@ -252,16 +252,16 @@ static Money DrawYearCategory (const Rec
 

	
 

	
 
/**
 
 * 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;
 

	
 
	/* Year header */
 
	SetDParam(0, year);
 
@@ -432,13 +432,13 @@ struct CompanyFinancesWindow : Window {
 
			case WID_CF_EXPS_PRICE2:
 
			case WID_CF_EXPS_PRICE3: {
 
				const Company *c = Company::Get((CompanyID)this->window_number);
 
				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;
 
			}
 

	
 
			case WID_CF_BALANCE_LINE:
 
				GfxFillRect(r.left, r.top, r.right, r.top, PC_BLACK);
0 comments (0 inline, 0 general)