1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

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>
This commit is contained in:
Martin Schwenke 2021-10-13 12:06:13 +11:00 committed by Volker Lendecke
parent ee17f5306c
commit c5061ebe21

View File

@ -1740,13 +1740,16 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
} }
} }
/* if (state.hs_len >= sizeof(state.header_str) - 1) {
* No +=, see man man strlcat
*/
state.hs_len = strlcat(state.header_str, "] ", sizeof(state.header_str));
if (state.hs_len >= sizeof(state.header_str)) {
goto full; 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) { if (!state.settings.debug_prefix_timestamp) {
state.hs_len += snprintf(state.header_str + state.hs_len, state.hs_len += snprintf(state.header_str + state.hs_len,