diff --git a/ompi/errhandler/errcode.h b/ompi/errhandler/errcode.h index b1246a1556..f6111069c2 100644 --- a/ompi/errhandler/errcode.h +++ b/ompi/errhandler/errcode.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; c-basic-offset:4 ; -*- */ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -12,6 +12,8 @@ * All rights reserved. * Copyright (c) 2006 University of Houston. All rights reserved. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -69,10 +71,13 @@ static inline bool ompi_mpi_errcode_is_invalid(int errcode) */ static inline int ompi_mpi_errcode_get_class (int errcode) { - ompi_mpi_errcode_t *err; + ompi_mpi_errcode_t *err = NULL; + + if (errcode >= 0) { + err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errcode); + /* If we get a bogus errcode, return MPI_ERR_UNKNOWN */ + } - err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errcode); - /* If we get a bogus errcode, return MPI_ERR_UNKNOWN */ if (NULL != err) { if ( err->code != MPI_UNDEFINED ) { return err->cls; @@ -93,6 +98,10 @@ static inline int ompi_mpi_errnum_is_class ( int errnum ) { ompi_mpi_errcode_t *err; + if (errno < 0) { + return false; + } + if ( errnum <= ompi_mpi_errcode_lastpredefined ) { /* Predefined error values represent an error code and an error class at the same time */ @@ -117,11 +126,14 @@ static inline int ompi_mpi_errnum_is_class ( int errnum ) */ static inline char* ompi_mpi_errnum_get_string (int errnum) { - ompi_mpi_errcode_t *err; - - err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum); - /* If we get a bogus errcode, return a string indicating that this - truly should not happen */ + ompi_mpi_errcode_t *err = NULL; + + if (errnum >= 0) { + err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum); + /* If we get a bogus errcode, return a string indicating that this + truly should not happen */ + } + if (NULL != err) { return err->errstring; } else { diff --git a/ompi/mpi/java/c/mpi_MPI.c b/ompi/mpi/java/c/mpi_MPI.c index 7036c19e46..761704a731 100644 --- a/ompi/mpi/java/c/mpi_MPI.c +++ b/ompi/mpi/java/c/mpi_MPI.c @@ -531,8 +531,11 @@ static void* getBuffer(JNIEnv *env, ompi_java_buffer_t **item, int size) opal_free_list_item_t *freeListItem; freeListItem = opal_free_list_get (&ompi_java_buffers); - ompi_java_exceptionCheck(env, NULL == freeListItem ? OMPI_ERROR : - OMPI_SUCCESS); + ompi_java_exceptionCheck(env, NULL == freeListItem ? MPI_ERR_NO_MEM : + MPI_SUCCESS); + if (NULL == freeListItem) { + return NULL; + } *item = (ompi_java_buffer_t*)freeListItem; return (*item)->buffer; @@ -1049,6 +1052,14 @@ void ompi_java_releasePtrArray(JNIEnv *env, jlongArray array, jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc) { + if (rc < 0) { + /* handle ompi error code */ + rc = ompi_errcode_get_mpi_code (rc); + /* ompi_mpi_errcode_get_class CAN NOT handle negative error codes. + * all Open MPI MPI error codes should be > 0. */ + assert (rc >= 0); + } + if(MPI_SUCCESS == rc) { return JNI_FALSE;