Skip to content

Commit

Permalink
errhan: cleanup with is_valid_err_class
Browse files Browse the repository at this point in the history
The code to check valid error class was imprecise. Add macros
is_valid_err_class and clean it up.
  • Loading branch information
hzhou committed Feb 2, 2022
1 parent 291b4f1 commit a658bdb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/mpi/errhan/errutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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-- */
Expand Down Expand Up @@ -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-- */
Expand Down Expand Up @@ -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-- */
Expand Down Expand Up @@ -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-- */
Expand Down

0 comments on commit a658bdb

Please sign in to comment.