Skip to content

Commit fe03602

Browse files
authored
Merge pull request #8163 from jsquyres/pr/keyval-parse-tweaks
Minor fix to keyval_parse
2 parents c7b968e + 8ed1d28 commit fe03602

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

opal/util/keyval_parse.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* reserved.
1515
* Copyright (c) 2018 Triad National Security, LLC. All rights
1616
* reserved.
17+
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved
1718
* $COPYRIGHT$
1819
*
1920
* Additional copyrights may follow
@@ -276,7 +277,7 @@ static int save_param_name (void)
276277

277278
static int add_to_env_str(char *var, char *val)
278279
{
279-
int sz, varsz, valsz, new_envsize;
280+
int sz, varsz = 0, valsz = 0, new_envsize;
280281
void *tmp;
281282

282283
if (NULL == var) {
@@ -286,22 +287,25 @@ static int add_to_env_str(char *var, char *val)
286287
varsz = strlen(var);
287288
if (NULL != val) {
288289
valsz = strlen(val);
289-
/* account for '=' */
290+
/* If we have a value, it will be preceeded by a '=', so be
291+
sure to account for that */
290292
valsz += 1;
291293
}
292294
sz = 0;
293295
if (NULL != env_str) {
294296
sz = strlen(env_str);
295-
/* account for ';' */
297+
/* If we have a valid variable, the whole clause will be
298+
terminated by a ';', so be sure to account for that */
296299
sz += 1;
297300
}
298-
/* add required new size incl NUL byte */
299-
sz += varsz+valsz+1;
301+
/* Sum the required new sizes, including space for a terminating
302+
\0 byte */
303+
sz += varsz + valsz + 1;
300304

301-
/* make sure we have sufficient space */
305+
/* Make sure we have sufficient space */
302306
new_envsize = envsize;
303307
while (new_envsize <= sz) {
304-
new_envsize *=2;
308+
new_envsize *= 2;
305309
}
306310

307311
if (NULL != env_str) {

0 commit comments

Comments
 (0)