From: Lennart Poettering Date: Thu, 20 Jul 2017 12:17:30 +0000 (+0200) Subject: string-util: optimize strshorten() a bit X-Git-Tag: v235~281^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47b33c7d5284492e5679ccfabafe8c9738de8cb3;p=thirdparty%2Fsystemd.git 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... --- diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 32878658636..5808b1280eb 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;