diff --git a/AUTHORS b/AUTHORS index 9f95750cc57..526be9e5f70 100644 --- a/AUTHORS +++ b/AUTHORS @@ -165,6 +165,7 @@ Josh Hursey, Indiana University, Oak Ridge National Laboratory, Los Alamos Natio jjhursey@open-mpi.org Joshua Gerrard enquiries@joshuagerrard.com + joshuagerrard+ompi-commit@protonmail.com Joshua Ladd, Mellanox jladd.mlnx@gmail.com joshual@mellanox.com diff --git a/ompi/errhandler/errhandler_predefined.c b/ompi/errhandler/errhandler_predefined.c index 46a07527473..8d235092b71 100644 --- a/ompi/errhandler/errhandler_predefined.c +++ b/ompi/errhandler/errhandler_predefined.c @@ -177,43 +177,84 @@ static void backend_fatal_aggregate(char *type, char *name, int *error_code, va_list arglist) { - char *arg, *prefix, *err_msg = "Unknown error"; - bool err_msg_need_free = false; + char *arg = NULL, *prefix = NULL, *err_msg = NULL; + const char* const unknown_error_code = "Error code: %d (no associated error message)"; + const char* const unknown_error = "Unknown error"; + const char* const unknown_prefix = "[?:?]"; + + // these do not own what they point to; they're + // here to avoid repeating expressions such as + // (NULL == foo) ? unknown_foo : foo + const char* usable_prefix = unknown_prefix; + const char* usable_err_msg = unknown_error; arg = va_arg(arglist, char*); va_end(arglist); - asprintf(&prefix, "[%s:%d]", ompi_process_info.nodename, - (int) ompi_process_info.pid); + if (asprintf(&prefix, "[%s:%d]", + ompi_process_info.nodename, + (int) ompi_process_info.pid) == -1) { + prefix = NULL; + // non-fatal, we could still go on to give useful information here... + opal_output(0, "%s", "Could not write node and PID to prefix"); + opal_output(0, "Node: %s", ompi_process_info.nodename); + opal_output(0, "PID: %d", (int) ompi_process_info.pid); + } if (NULL != error_code) { err_msg = ompi_mpi_errnum_get_string(*error_code); if (NULL == err_msg) { - err_msg_need_free = true; - asprintf(&err_msg, "Error code: %d (no associated error message)", - *error_code); + if (asprintf(&err_msg, unknown_error_code, + *error_code) == -1) { + err_msg = NULL; + opal_output(0, "%s", "Could not write to err_msg"); + opal_output(0, unknown_error_code, *error_code); + } } } + usable_prefix = (NULL == prefix) ? unknown_prefix : prefix; + usable_err_msg = (NULL == err_msg) ? unknown_error : err_msg; + if (NULL != name) { opal_show_help("help-mpi-errors.txt", - "mpi_errors_are_fatal", false, - prefix, (NULL == arg) ? "" : "in", + "mpi_errors_are_fatal", + false, + usable_prefix, + (NULL == arg) ? "" : "in", (NULL == arg) ? "" : arg, - prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid, - prefix, type, name, prefix, err_msg, prefix, type, prefix); + usable_prefix, + OMPI_PROC_MY_NAME->jobid, + OMPI_PROC_MY_NAME->vpid, + usable_prefix, + type, + name, + usable_prefix, + usable_err_msg, + usable_prefix, + type, + usable_prefix); } else { opal_show_help("help-mpi-errors.txt", - "mpi_errors_are_fatal unknown handle", false, - prefix, (NULL == arg) ? "" : "in", + "mpi_errors_are_fatal unknown handle", + false, + usable_prefix, + (NULL == arg) ? "" : "in", (NULL == arg) ? "" : arg, - prefix, OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid, - prefix, type, prefix, err_msg, prefix, type, prefix); + usable_prefix, + OMPI_PROC_MY_NAME->jobid, + OMPI_PROC_MY_NAME->vpid, + usable_prefix, + type, + usable_prefix, + usable_err_msg, + usable_prefix, + type, + usable_prefix); } - if (err_msg_need_free) { - free(err_msg); - } + free(prefix); + free(err_msg); } /*