diff --git a/opal/class/opal_pointer_array.c b/opal/class/opal_pointer_array.c index 3c948d30032..0bbbb5a2277 100644 --- a/opal/class/opal_pointer_array.c +++ b/opal/class/opal_pointer_array.c @@ -166,6 +166,10 @@ int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, { assert(table != NULL); + if (OPAL_UNLIKELY(0 > index)) { + return OPAL_ERROR; + } + /* expand table if required to set a specific index */ OPAL_THREAD_LOCK(&(table->lock)); diff --git a/opal/class/opal_pointer_array.h b/opal/class/opal_pointer_array.h index 8271fe50ba1..87b45b1a337 100644 --- a/opal/class/opal_pointer_array.h +++ b/opal/class/opal_pointer_array.h @@ -33,6 +33,7 @@ #include "opal/threads/mutex.h" #include "opal/class/opal_object.h" +#include "opal/prefetch.h" BEGIN_C_DECLS @@ -124,7 +125,7 @@ static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table, { void *p; - if( table->size <= element_index ) { + if( OPAL_UNLIKELY(0 > element_index || table->size <= element_index) ) { return NULL; } OPAL_THREAD_LOCK(&(table->lock));