From 3970b0613409ddd1e1c595f2326b2db83bd6b9bb Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 11 Sep 2018 17:59:37 -0400 Subject: [PATCH] misc: passing a bool to va_start() is undefined According to clang on MacOS, passing a bool parameter -- which undergoes default parameter promotion -- to va_start() results in undefined behavior. So just change these params to int and avoid the issue. Signed-off-by: Jeff Squyres --- opal/util/os_path.c | 3 ++- opal/util/os_path.h | 10 ++++++++-- opal/util/show_help.c | 16 ++++++++-------- opal/util/show_help.h | 15 ++++++++++----- orte/util/show_help.c | 6 +++--- orte/util/show_help.h | 6 +++--- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/opal/util/os_path.c b/opal/util/os_path.c index 251a6107fc..ad8792c015 100644 --- a/opal/util/os_path.c +++ b/opal/util/os_path.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -32,7 +33,7 @@ static const char *path_sep = OPAL_PATH_SEP; -char *opal_os_path(bool relative, ...) +char *opal_os_path(int relative, ...) { va_list ap; char *element, *path; diff --git a/opal/util/os_path.h b/opal/util/os_path.h index 4c2db908f4..db3d9dcbe7 100644 --- a/opal/util/os_path.h +++ b/opal/util/os_path.h @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -62,8 +63,13 @@ BEGIN_C_DECLS * provided path elements, separated by the path separator character * appropriate to the local operating system. The path_name string has been malloc'd * and therefore the user is responsible for free'ing the field. -*/ -OPAL_DECLSPEC char *opal_os_path(bool relative, ...) __opal_attribute_malloc__ __opal_attribute_sentinel__ __opal_attribute_warn_unused_result__; + * + * Note that the "relative" argument is int instead of bool, because + * passing a parameter that undergoes default argument promotion to + * va_start() has undefined behavior (according to clang warnings on + * MacOS High Sierra). + */ +OPAL_DECLSPEC char *opal_os_path(int relative, ...) __opal_attribute_malloc__ __opal_attribute_sentinel__ __opal_attribute_warn_unused_result__; /** * Convert the path to be OS friendly. On UNIX this function will diff --git a/opal/util/show_help.c b/opal/util/show_help.c index 18c82ccbff..b05fd19231 100644 --- a/opal/util/show_help.c +++ b/opal/util/show_help.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ @@ -48,9 +48,9 @@ static char **search_dirs = NULL; * Local functions */ static int opal_show_vhelp_internal(const char *filename, const char *topic, - bool want_error_header, va_list arglist); + int want_error_header, va_list arglist); static int opal_show_help_internal(const char *filename, const char *topic, - bool want_error_header, ...); + int want_error_header, ...); opal_show_help_fn_t opal_show_help = opal_show_help_internal; opal_show_vhelp_fn_t opal_show_vhelp = opal_show_vhelp_internal; @@ -89,7 +89,7 @@ int opal_show_help_finalize(void) * not optimization. :-) */ static int array2string(char **outstring, - bool want_error_header, char **lines) + int want_error_header, char **lines) { int i, count; size_t len; @@ -293,7 +293,7 @@ static int load_array(char ***array, const char *filename, const char *topic) } char *opal_show_help_vstring(const char *filename, const char *topic, - bool want_error_header, va_list arglist) + int want_error_header, va_list arglist) { int rc; char *single_string, *output, **array = NULL; @@ -317,7 +317,7 @@ char *opal_show_help_vstring(const char *filename, const char *topic, } char *opal_show_help_string(const char *filename, const char *topic, - bool want_error_handler, ...) + int want_error_handler, ...) { char *output; va_list arglist; @@ -331,7 +331,7 @@ char *opal_show_help_string(const char *filename, const char *topic, } static int opal_show_vhelp_internal(const char *filename, const char *topic, - bool want_error_header, va_list arglist) + int want_error_header, va_list arglist) { char *output; @@ -349,7 +349,7 @@ static int opal_show_vhelp_internal(const char *filename, const char *topic, } static int opal_show_help_internal(const char *filename, const char *topic, - bool want_error_header, ...) + int want_error_header, ...) { va_list arglist; int rc; diff --git a/opal/util/show_help.h b/opal/util/show_help.h index 8806f05906..b0632c62cd 100644 --- a/opal/util/show_help.h +++ b/opal/util/show_help.h @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008-2011 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -127,9 +127,14 @@ OPAL_DECLSPEC int opal_show_help_finalize(void); * (typically $prefix/share/openmpi), and looks up the message * based on the topic, and displays it. If want_error_header is * true, a header and footer of asterisks are also displayed. + * + * Note that the "want_error_header" argument is int instead of bool, + * because passing a parameter that undergoes default argument + * promotion to va_start() has undefined behavior (according to clang + * warnings on MacOS High Sierra). */ typedef int (*opal_show_help_fn_t)(const char *filename, const char *topic, - bool want_error_header, ...); + int want_error_header, ...); OPAL_DECLSPEC extern opal_show_help_fn_t opal_show_help; /** @@ -137,7 +142,7 @@ OPAL_DECLSPEC extern opal_show_help_fn_t opal_show_help; * a va_list form of varargs. */ typedef int (*opal_show_vhelp_fn_t)(const char *filename, const char *topic, - bool want_error_header, va_list ap); + int want_error_header, va_list ap); OPAL_DECLSPEC extern opal_show_vhelp_fn_t opal_show_vhelp; /** @@ -146,7 +151,7 @@ OPAL_DECLSPEC extern opal_show_vhelp_fn_t opal_show_vhelp; */ OPAL_DECLSPEC char* opal_show_help_string(const char *filename, const char *topic, - bool want_error_header, ...); + int want_error_header, ...); /** * This function does the same thing as opal_show_help_string(), but @@ -154,7 +159,7 @@ OPAL_DECLSPEC char* opal_show_help_string(const char *filename, */ OPAL_DECLSPEC char* opal_show_help_vstring(const char *filename, const char *topic, - bool want_error_header, va_list ap); + int want_error_header, va_list ap); /** * This function adds another search location for the files that diff --git a/orte/util/show_help.c b/orte/util/show_help.c index 1b68c94580..e49c38c7ca 100644 --- a/orte/util/show_help.c +++ b/orte/util/show_help.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008-2011 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012-2013 Los Alamos National Security, LLC. * All rights reserved. * Copyright (c) 2016-2017 Intel, Inc. All rights reserved. @@ -591,7 +591,7 @@ void orte_show_help_finalize(void) } int orte_show_help(const char *filename, const char *topic, - bool want_error_header, ...) + int want_error_header, ...) { int rc = ORTE_SUCCESS; va_list arglist; @@ -623,7 +623,7 @@ static void cbfunc(int status, void *cbdata) } int orte_show_help_norender(const char *filename, const char *topic, - bool want_error_header, const char *output) + int want_error_header, const char *output) { int rc = ORTE_SUCCESS; int8_t have_output = 1; diff --git a/orte/util/show_help.h b/orte/util/show_help.h index cb572e4634..8d32f48475 100644 --- a/orte/util/show_help.h +++ b/orte/util/show_help.h @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008-2011 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved. * $COPYRIGHT$ * @@ -78,7 +78,7 @@ ORTE_DECLSPEC void orte_show_help_finalize(void); * (e.g., cray). */ ORTE_DECLSPEC int orte_show_help(const char *filename, const char *topic, - bool want_error_header, ...); + int want_error_header, ...); /** * Exactly the same as orte_show_help, but pass in a rendered string, @@ -86,7 +86,7 @@ ORTE_DECLSPEC int orte_show_help(const char *filename, const char *topic, */ ORTE_DECLSPEC int orte_show_help_norender(const char *filename, const char *topic, - bool want_error_header, + int want_error_header, const char *output); /**