diff --git a/src/mpi/errhan/errutil.c b/src/mpi/errhan/errutil.c index 22abb4c7a0c..4d5167b8816 100644 --- a/src/mpi/errhan/errutil.c +++ b/src/mpi/errhan/errutil.c @@ -102,6 +102,11 @@ * their sizes, and masks and shifts that may be used to extract them. */ +/* whether an errcode is a generic error class */ +#define is_valid_error_class(errcode) \ + ((errcode >= 0 && errcode <= MPICH_ERR_LAST_CLASS) || \ + (errcode > MPICH_ERR_FIRST_MPIX && errcode <= MPICH_ERR_LAST_MPIX)) + static int did_err_init = FALSE; /* helps us solve a bootstrapping problem */ /* A few prototypes. These routines are called from the MPIR_Err_return @@ -686,7 +691,7 @@ static void CombineSpecificCodes(int error1_code, int error2_code, int error2_cl static const char *get_class_msg(int error_class) { - if (error_class >= 0 && error_class < MPIR_MAX_ERROR_CLASS_INDEX) { + if (is_valid_error_class(error_class)) { return classToMsg[error_class]; } else { /* --BEGIN ERROR HANDLING-- */ @@ -743,7 +748,7 @@ static void CombineSpecificCodes(int error1_code, int error2_code, int error2_cl static const char *get_class_msg(int error_class) { - if (error_class >= 0 && error_class < MPIR_MAX_ERROR_CLASS_INDEX) { + if (is_valid_error_class(error_class)) { return generic_err_msgs[class_to_index[error_class]].long_name; } else { /* --BEGIN ERROR HANDLING-- */ @@ -1242,7 +1247,7 @@ static void MPIR_Err_print_stack_string(int errcode, char *str, int maxlen) static const char *get_class_msg(int error_class) { - if (error_class >= 0 && error_class < MPIR_MAX_ERROR_CLASS_INDEX) { + if (is_valid_error_class(error_class)) { return generic_err_msgs[class_to_index[error_class]].long_name; } else { /* --BEGIN ERROR HANDLING-- */ @@ -1813,8 +1818,9 @@ static int checkErrcodeIsValid(int errcode) int ring_id, generic_idx, ring_idx; /* If the errcode is a class, then it is valid */ - if (errcode <= MPIR_MAX_ERROR_CLASS_INDEX && errcode >= 0) + if (is_valid_error_class(errcode)) { return 0; + } if (convertErrcodeToIndexes(errcode, &ring_idx, &ring_id, &generic_idx) != 0) { /* --BEGIN ERROR HANDLING-- */