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:
@@ -76,7 +76,7 @@ private:
|
||||
|
||||
/* Constants for sorting the bridges */
|
||||
static const StringID sorter_names[];
|
||||
static GUIBridgeList::SortFunction * const sorter_funcs[];
|
||||
static const std::initializer_list<GUIBridgeList::SortFunction * const> sorter_funcs;
|
||||
|
||||
/* Internal variables */
|
||||
TileIndex start_tile;
|
||||
@@ -298,7 +298,7 @@ public:
|
||||
Listing BuildBridgeWindow::last_sorting = {true, 2};
|
||||
|
||||
/** Available bridge sorting functions. */
|
||||
GUIBridgeList::SortFunction * const BuildBridgeWindow::sorter_funcs[] = {
|
||||
const std::initializer_list<GUIBridgeList::SortFunction * const> BuildBridgeWindow::sorter_funcs = {
|
||||
&BridgeIndexSorter,
|
||||
&BridgePriceSorter,
|
||||
&BridgeSpeedSorter
|
||||
|
||||
Reference in New Issue
Block a user