Skip to content

Commit 7f4f8fd

Browse files
authored
Merge pull request #8581 from devreal/fix-opal-argv-warn
Make sure to never allocate zero-length memory buffer in opal_argv_join_range
2 parents 9f845f0 + ee462f1 commit 7f4f8fd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

opal/util/argv.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter)
343343

344344
/* Bozo case */
345345

346-
if (NULL == argv || NULL == argv[0] || (int)start > opal_argv_count(argv)) {
346+
if (NULL == argv || NULL == argv[0] || (int)start >= opal_argv_count(argv)) {
347347
return strdup("");
348348
}
349349

@@ -354,10 +354,15 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter)
354354
str_len += strlen(*p) + 1;
355355
}
356356

357+
if (0 == str_len) {
358+
return strdup("");
359+
}
360+
357361
/* Allocate the string. */
358362

359-
if (NULL == (str = (char*) malloc(str_len)))
363+
if (NULL == (str = (char*) malloc(str_len))) {
360364
return NULL;
365+
}
361366

362367
/* Loop filling in the string. */
363368

0 commit comments

Comments
 (0)