mirror of
https://github.com/libretro/RetroArch
synced 2025-01-16 16:29:28 +00:00
Change bounds to a const variable
Add one more bounds check
This commit is contained in:
parent
e8b381680a
commit
adbc71ce46
@ -50,6 +50,7 @@ static void input_state_set_last(unsigned port, unsigned device,
|
||||
{
|
||||
unsigned i;
|
||||
InputListElement *element = NULL;
|
||||
const int MAX_ID = sizeof(element->state) / sizeof(int16_t);
|
||||
|
||||
if (!input_state_list)
|
||||
mylist_create(&input_state_list, 16,
|
||||
@ -62,7 +63,7 @@ static void input_state_set_last(unsigned port, unsigned device,
|
||||
if ( (element->port == port) &&
|
||||
(element->device == device) &&
|
||||
(element->index == index) &&
|
||||
(id >= 0 && id < (sizeof(element->state) / sizeof(int16_t)))
|
||||
(id >= 0 && id < MAX_ID)
|
||||
)
|
||||
{
|
||||
element->state[id] = value;
|
||||
@ -75,7 +76,8 @@ static void input_state_set_last(unsigned port, unsigned device,
|
||||
element->port = port;
|
||||
element->device = device;
|
||||
element->index = index;
|
||||
element->state[id] = value;
|
||||
if (id >= 0 && id < MAX_ID)
|
||||
element->state[id] = value;
|
||||
}
|
||||
|
||||
static int16_t input_state_get_last(unsigned port,
|
||||
@ -91,11 +93,12 @@ static int16_t input_state_get_last(unsigned port,
|
||||
{
|
||||
InputListElement *element =
|
||||
(InputListElement*)input_state_list->data[i];
|
||||
const int MAX_ID = sizeof(element->state) / sizeof(int16_t);
|
||||
|
||||
if ( (element->port == port) &&
|
||||
(element->device == device) &&
|
||||
(element->index == index) &&
|
||||
(id >= 0 && id < (sizeof(element->state) / sizeof(int16_t)))
|
||||
(id >= 0 && id < MAX_ID)
|
||||
)
|
||||
return element->state[id];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user