From adbc71ce460f7d7f50d661ec8ccd181b82bddf31 Mon Sep 17 00:00:00 2001 From: Dwedit Date: Mon, 28 May 2018 12:14:04 -0500 Subject: [PATCH] Change bounds to a const variable Add one more bounds check --- runahead/dirty_input.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runahead/dirty_input.c b/runahead/dirty_input.c index e772a97cee..542b36f6b8 100644 --- a/runahead/dirty_input.c +++ b/runahead/dirty_input.c @@ -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]; }