Skip to content

Commit 994ed60

Browse files
committed
Improving opal_pointer_array bounds checking (using
OPAL_UNLIKELY).
1 parent 06dbcc1 commit 994ed60

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

opal/class/opal_pointer_array.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ int opal_pointer_array_set_item(opal_pointer_array_t *table, int index,
166166
{
167167
assert(table != NULL);
168168

169+
if (OPAL_UNLIKELY(0 > index)) {
170+
return OPAL_ERROR;
171+
}
172+
169173
/* expand table if required to set a specific index */
170174

171175
OPAL_THREAD_LOCK(&(table->lock));

opal/class/opal_pointer_array.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "opal/threads/mutex.h"
3535
#include "opal/class/opal_object.h"
36+
#include "opal/prefetch.h"
3637

3738
BEGIN_C_DECLS
3839

@@ -124,7 +125,7 @@ static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table,
124125
{
125126
void *p;
126127

127-
if( table->size <= element_index ) {
128+
if( OPAL_UNLIKELY(0 > element_index || table->size <= element_index) ) {
128129
return NULL;
129130
}
130131
OPAL_THREAD_LOCK(&(table->lock));

0 commit comments

Comments
 (0)