Codechange: Make sort list function lists safer. (#12574)
GUIList has a pointer only to the start of each sort/filter func list, which has the potential for UB as it is unable to validate that the selected sort or filter type is in range. Use a std::span instead and check if the selected type is in range before using it.
This commit is contained in:
+4
-4
@@ -609,8 +609,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||
|
||||
static Listing last_sorting; ///< Default sorting of #GUIGRFConfigList.
|
||||
static Filtering last_filtering; ///< Default filtering of #GUIGRFConfigList.
|
||||
static GUIGRFConfigList::SortFunction * const sorter_funcs[]; ///< Sort functions of the #GUIGRFConfigList.
|
||||
static GUIGRFConfigList::FilterFunction * const filter_funcs[]; ///< Filter functions of the #GUIGRFConfigList.
|
||||
static const std::initializer_list<GUIGRFConfigList::SortFunction * const> sorter_funcs; ///< Sort functions of the #GUIGRFConfigList.
|
||||
static const std::initializer_list<GUIGRFConfigList::FilterFunction * const> filter_funcs; ///< Filter functions of the #GUIGRFConfigList.
|
||||
|
||||
GUIGRFConfigList avails; ///< Available (non-active) grfs.
|
||||
const GRFConfig *avail_sel; ///< Currently selected available grf. \c nullptr is none is selected.
|
||||
@@ -1586,11 +1586,11 @@ void ShowMissingContentWindow(const GRFConfig *list)
|
||||
Listing NewGRFWindow::last_sorting = {false, 0};
|
||||
Filtering NewGRFWindow::last_filtering = {false, 0};
|
||||
|
||||
NewGRFWindow::GUIGRFConfigList::SortFunction * const NewGRFWindow::sorter_funcs[] = {
|
||||
const std::initializer_list<NewGRFWindow::GUIGRFConfigList::SortFunction * const> NewGRFWindow::sorter_funcs = {
|
||||
&NameSorter,
|
||||
};
|
||||
|
||||
NewGRFWindow::GUIGRFConfigList::FilterFunction * const NewGRFWindow::filter_funcs[] = {
|
||||
const std::initializer_list<NewGRFWindow::GUIGRFConfigList::FilterFunction * const> NewGRFWindow::filter_funcs = {
|
||||
&TagNameFilter,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user