From 994ed60b3dd963c5c48fb4ab8c9a49c9237120f6 Mon Sep 17 00:00:00 2001 From: Alejandro Vilches Date: Fri, 10 Jul 2015 15:07:30 -0700 Subject: [PATCH] Improving opal_pointer_array bounds checking (using OPAL_UNLIKELY). --- opal/class/opal_pointer_array.c | 4 ++++ opal/class/opal_pointer_array.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) 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));