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...
This commit is contained in:
Lennart Poettering 2017-07-20 14:17:30 +02:00
parent c165d97d16
commit 47b33c7d52
1 changed files with 1 additions and 1 deletions

View File

@ -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;