1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

debug: Optimise early return when header string buffer is full

The existing check is for truncation, not whether the buffer is full.
However, if the buffer is full (i.e. hs_len == sizeof(header_str) - 1)
then there's no use trying subsequent snprintf() calls because there
will be one byte available that already contains the NUL-terminator.
A subsequent call will just do a no-op truncation.

Check for full buffer instead.

This might be confusing because it isn't the standard check that is
done after snprintf() calls.  Is it worth it for a rare corner case?

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 20:40:34 +11:00 committed by Volker Lendecke
parent c5061ebe21
commit cb70eea053

View File

@ -1698,7 +1698,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
"[%s, %2d",
tvbuf.buf,
level);
if (state.hs_len >= sizeof(state.header_str)) {
if (state.hs_len >= sizeof(state.header_str) - 1) {
goto full;
}
@ -1711,7 +1711,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
sizeof(state.header_str) - state.hs_len,
", pid=%u",
(unsigned int)getpid());
if (state.hs_len >= sizeof(state.header_str)) {
if (state.hs_len >= sizeof(state.header_str) - 1) {
goto full;
}
}
@ -1724,7 +1724,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
(unsigned int)getegid(),
(unsigned int)getuid(),
(unsigned int)getgid());
if (state.hs_len >= sizeof(state.header_str)) {
if (state.hs_len >= sizeof(state.header_str) - 1) {
goto full;
}
}
@ -1735,9 +1735,6 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
sizeof(state.header_str) - state.hs_len,
", class=%s",
classname_table[cls]);
if (state.hs_len >= sizeof(state.header_str)) {
goto full;
}
}
if (state.hs_len >= sizeof(state.header_str) - 1) {