From cb655315330f5435b7849d256e33f8c148fd38d6 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 18 Nov 2021 09:34:54 +0100 Subject: [PATCH] Simplify sc_str_truncate() Use strcspn() to get the prefix length directly. --- app/src/util/str.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/util/str.c b/app/src/util/str.c index fdc1a8b3..3bd2752f 100644 --- a/app/src/util/str.c +++ b/app/src/util/str.c @@ -295,10 +295,7 @@ error: size_t sc_str_truncate(char *data, size_t len, const char *endchars) { data[len - 1] = '\0'; - char *eol = strpbrk(data, endchars); - if (eol) { - *eol = '\0'; - len = eol - data; - } - return len; + size_t idx = strcspn(data, endchars); + data[idx] = '\0'; + return idx; }