From dd5771a663622a14e16971f2afb119fb91c6fade Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 20 Jul 2017 14:17:30 +0200 Subject: [PATCH] string-util: optimize strshorten() a bit There's no reason to determine the full length of the string, it's sufficient to know whether it is larger than the intended size... --- src/basic/string-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 4bfce5a5d..5172ac775 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -562,7 +562,7 @@ bool nulstr_contains(const char *nulstr, const char *needle) { char* strshorten(char *s, size_t l) { assert(s); - if (l < strlen(s)) + if (strnlen(s, l+1) > l) s[l] = 0; return s; -- 2.30.2