From 19c863b6fba83e494f36f22b81350e73eccadec6 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 31 Oct 2020 04:11:49 -0700 Subject: [PATCH 1/2] keyval_parse.c: ensure to init values Coverity complained about uninitialized variables; ensure that they are initialized to 0 in all cases. Signed-off-by: Jeff Squyres (cherry picked from commit eac0ab5c3a450174c4ec48ae6447ee01e80401e4) --- opal/util/keyval_parse.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opal/util/keyval_parse.c b/opal/util/keyval_parse.c index b938e06ca2..4123bbf2e7 100644 --- a/opal/util/keyval_parse.c +++ b/opal/util/keyval_parse.c @@ -12,6 +12,9 @@ * All rights reserved. * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights * reserved. + * Copyright (c) 2018 Triad National Security, LLC. All rights + * reserved. + * Copyright (c) 2020 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -274,7 +277,7 @@ static int save_param_name (void) static int add_to_env_str(char *var, char *val) { - int sz, varsz, valsz, new_envsize; + int sz, varsz = 0, valsz = 0, new_envsize; void *tmp; if (NULL == var) { From c10a85eea33141640f99566ab0ffc28ff16033e5 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 31 Oct 2020 04:12:27 -0700 Subject: [PATCH 2/2] keyval_parse.c: update whitespace/comments Slightly improve comments and update some whitespace. No code or logic changes. Signed-off-by: Jeff Squyres (cherry picked from commit 8ed1d28fb4afcc54bc4d093bfcc53acae3d2fa58) --- opal/util/keyval_parse.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/opal/util/keyval_parse.c b/opal/util/keyval_parse.c index 4123bbf2e7..2cdb57a510 100644 --- a/opal/util/keyval_parse.c +++ b/opal/util/keyval_parse.c @@ -287,22 +287,25 @@ static int add_to_env_str(char *var, char *val) varsz = strlen(var); if (NULL != val) { valsz = strlen(val); - /* account for '=' */ + /* If we have a value, it will be preceeded by a '=', so be + sure to account for that */ valsz += 1; } sz = 0; if (NULL != env_str) { sz = strlen(env_str); - /* account for ';' */ + /* If we have a valid variable, the whole clause will be + terminated by a ';', so be sure to account for that */ sz += 1; } - /* add required new size incl NUL byte */ - sz += varsz+valsz+1; + /* Sum the required new sizes, including space for a terminating + \0 byte */ + sz += varsz + valsz + 1; - /* make sure we have sufficient space */ + /* Make sure we have sufficient space */ new_envsize = envsize; while (new_envsize <= sz) { - new_envsize *=2; + new_envsize *= 2; } if (NULL != env_str) {