From d8e639ecba373b3ea8b0a007fe2c67aa8325f369 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 22 May 2024 11:17:09 +0200 Subject: [PATCH] dev-cache: collapsing slashes counts string size _collapse_slashes() already goes through the whole string, so just return now already known string length. --- lib/device/dev-cache.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 47d8daa23..93fe7284c 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -854,8 +854,9 @@ static int _insert_dev(const char *path, dev_t d) /* * Get rid of extra slashes in the path string. */ -static void _collapse_slashes(char *str) +static size_t _collapse_slashes(char *str) { + char *start = str; char *ptr; int was_slash = 0; @@ -870,7 +871,9 @@ static void _collapse_slashes(char *str) *str++ = *ptr; } - *str = *ptr; + *str = 0; + + return (str - start); } static int _insert_dir(const char *dir) @@ -884,8 +887,8 @@ static int _insert_dir(const char *dir) log_debug_devs("Dir path %s is too long", path); return 0; } - _collapse_slashes(path); - len = strlen(path); + + len = _collapse_slashes(path); if (len && path[len - 1] != '/') path[len++] = '/';