chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
07d8f20
)
string-util: optimize strshorten() a bit
author
Lennart Poettering
<lennart@poettering.net>
Thu, 20 Jul 2017 12:17:30 +0000
(14:17 +0200)
committer
Sven Eden
<yamakuzure@gmx.net>
Thu, 20 Jul 2017 12:17:30 +0000
(14:17 +0200)
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
patch
|
blob
|
history
diff --git
a/src/basic/string-util.c
b/src/basic/string-util.c
index 4bfce5a5dca163c3572e0a99d41b678480afa7fb..5172ac7756a3c32e1f8c39f632205132343fd36b 100644
(file)
--- a/
src/basic/string-util.c
+++ b/
src/basic/string-util.c
@@
-562,7
+562,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;