summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2021-10-13 12:06:13 +1100
committerVolker Lendecke <vl@samba.org>2021-10-14 10:21:30 +0000
commitc5061ebe2146b6e8257205a4ad9ba69d1caa4c7d (patch)
treed0b7e1bd380fa42223599eef8c4cda33739f0359 /lib
parentee17f5306c3db1b6d950a9ea7d1787cac96a6d9d (diff)
downloadsamba-c5061ebe2146b6e8257205a4ad9ba69d1caa4c7d.tar.gz
debug: Optimise to avoid walking the header string
strlcat() needs to walk to the end of its first argument. However, but the length of state.header_str is already known, so optimise by manually appending the extra characters if they will fit. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/debug.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/util/debug.c b/lib/util/debug.c
index d48a56ee70d..c18726759e7 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1740,13 +1740,16 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
}
}
- /*
- * No +=, see man man strlcat
- */
- state.hs_len = strlcat(state.header_str, "] ", sizeof(state.header_str));
- if (state.hs_len >= sizeof(state.header_str)) {
+ if (state.hs_len >= sizeof(state.header_str) - 1) {
goto full;
}
+ state.header_str[state.hs_len] = ']';
+ state.hs_len++;
+ if (state.hs_len < sizeof(state.header_str) - 1) {
+ state.header_str[state.hs_len] = ' ';
+ state.hs_len++;
+ }
+ state.header_str[state.hs_len] = '\0';
if (!state.settings.debug_prefix_timestamp) {
state.hs_len += snprintf(state.header_str + state.hs_len,