From 7973e87b2f2eb778667c24b674e7f7f7ffec5fd1 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 26 Mar 2019 00:58:14 +0800 Subject: [PATCH] Additional check with NULL or empty string (now same behaviour as POSIX version) --- modules/src/system/basename.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/src/system/basename.c b/modules/src/system/basename.c index 21736bbce..04322085e 100644 --- a/modules/src/system/basename.c +++ b/modules/src/system/basename.c @@ -12,12 +12,22 @@ void sys_basename(char *str, register char *dst) register char *p2 = p1; register char *end; register char *start; + int len; - int len = strlen(str); + if ((str == NULL) || (*str == '\0')) + { + dst[0] = '.'; + dst[1] = '\0'; + return; + } + + len = strlen(str); /* Point to the end of the string. */ p1 = p1 + len - 1; end = p1; + + while ((*p1 == '/') || (*p1 == '\\')) { if (p1 == str)