path-util: handle NULL inputs in last_path_component()
This commit is contained in:
parent
5f7ecd610c
commit
77e0a1b5e0
|
@ -750,6 +750,9 @@ const char *last_path_component(const char *path) {
|
||||||
|
|
||||||
unsigned l, k;
|
unsigned l, k;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
l = k = strlen(path);
|
l = k = strlen(path);
|
||||||
if (l == 0) /* special case — an empty string */
|
if (l == 0) /* special case — an empty string */
|
||||||
return path;
|
return path;
|
||||||
|
|
|
@ -406,6 +406,7 @@ static void test_file_in_same_dir(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_last_path_component(void) {
|
static void test_last_path_component(void) {
|
||||||
|
assert_se(last_path_component(NULL) == NULL);
|
||||||
assert_se(streq(last_path_component("a/b/c"), "c"));
|
assert_se(streq(last_path_component("a/b/c"), "c"));
|
||||||
assert_se(streq(last_path_component("a/b/c/"), "c/"));
|
assert_se(streq(last_path_component("a/b/c/"), "c/"));
|
||||||
assert_se(streq(last_path_component("/"), "/"));
|
assert_se(streq(last_path_component("/"), "/"));
|
||||||
|
|
Loading…
Reference in New Issue