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:
parent
c165d97d16
commit
47b33c7d52
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue