[dm-devel] [PATCH 05/35] libmultipath: improve strchop()

mwilck at suse.com mwilck at suse.com
Thu Jul 9 10:15:50 UTC 2020


From: Martin Wilck <mwilck at suse.com>

strchop() returns size_t, so have it work with size_t, too. Also,
avoid the unnecessary second call to strlen().

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 libmultipath/util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libmultipath/util.c b/libmultipath/util.c
index 51c38c8..28d0168 100644
--- a/libmultipath/util.c
+++ b/libmultipath/util.c
@@ -26,11 +26,11 @@
 size_t
 strchop(char *str)
 {
-	int i;
+	size_t i;
 
-	for (i=strlen(str)-1; i >=0 && isspace(str[i]); --i) ;
+	for (i = strlen(str) - 1; i != (size_t) -1 && isspace(str[i]); i--) ;
 	str[++i] = '\0';
-	return strlen(str);
+	return i;
 }
 
 int
-- 
2.26.2





More information about the dm-devel mailing list