Skip to content

Commit 8b7e577

Browse files
authored
Merge pull request #12632 from ggouaillardet/topic/opal_basename
opal: fix opal_basename() for single character filenames
2 parents 7b28730 + dd34ecf commit 8b7e577

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

opal/util/basename.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
13-
* Copyright (c) 2014-2015 Research Organization for Information Science
14-
* and Technology (RIST). All rights reserved.
13+
* Copyright (c) 2014-2024 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2014 Intel, Inc. All rights reserved.
1616
* $COPYRIGHT$
1717
*
@@ -77,16 +77,18 @@ char *opal_basename(const char *filename)
7777

7878
/* Remove trailing sep's (note that we already know that strlen > 0) */
7979
tmp = strdup(filename);
80-
for (i = strlen(tmp) - 1; i > 0; --i) {
81-
if (sep == tmp[i]) {
82-
tmp[i] = '\0';
83-
} else {
84-
break;
80+
if (1 < strlen(tmp)) {
81+
for (i = strlen(tmp) - 1; i > 0; --i) {
82+
if (sep == tmp[i]) {
83+
tmp[i] = '\0';
84+
} else {
85+
break;
86+
}
87+
}
88+
if (0 == i) {
89+
tmp[0] = sep;
90+
return tmp;
8591
}
86-
}
87-
if (0 == i) {
88-
tmp[0] = sep;
89-
return tmp;
9092
}
9193

9294
/* Look for the final sep */

0 commit comments

Comments
 (0)