From 47b33c7d5284492e5679ccfabafe8c9738de8cb3 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 3287865863..5808b1280e 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -558,7 +558,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;