Skip to content

Commit 47b33c7

Browse files
committed
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...
1 parent c165d97 commit 47b33c7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/basic/string-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ bool nulstr_contains(const char *nulstr, const char *needle) {
558558
char* strshorten(char *s, size_t l) {
559559
assert(s);
560560

561-
if (l < strlen(s))
561+
if (strnlen(s, l+1) > l)
562562
s[l] = 0;
563563

564564
return s;

0 commit comments

Comments
 (0)