Skip to content

Commit 490874c

Browse files
authored
Merge pull request #17 from tearfur/malformed-logs
fix: malformed logs produced by `struct_utp_context::log()`
2 parents 2d29ce9 + eedd8b9 commit 490874c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

utp_internal.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,21 +3388,26 @@ void struct_utp_context::log(int level, utp_socket *socket, char const *fmt, ...
33883388

33893389
va_list va;
33903390
va_start(va, fmt);
3391-
log_unchecked(socket, fmt, va);
3391+
log_impl(socket, fmt, va);
33923392
va_end(va);
33933393
}
33943394

33953395
void struct_utp_context::log_unchecked(utp_socket *socket, char const *fmt, ...)
33963396
{
33973397
va_list va;
3398+
va_start(va, fmt);
3399+
log_impl(socket, fmt, va);
3400+
va_end(va);
3401+
}
3402+
3403+
void struct_utp_context::log_impl(utp_socket *socket, char const *fmt, va_list va)
3404+
{
33983405
char buf[4096];
33993406

3400-
va_start(va, fmt);
34013407
vsnprintf(buf, 4096, fmt, va);
34023408
buf[4095] = '\0';
3403-
va_end(va);
34043409

3405-
utp_call_log(this, socket, (const byte *)buf);
3410+
utp_call_log(this, socket, reinterpret_cast<const byte *>(buf));
34063411
}
34073412

34083413
inline bool struct_utp_context::would_log(int level)

utp_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ struct struct_utp_context {
182182
bool log_normal:1; // log normal events?
183183
bool log_mtu:1; // log MTU related events?
184184
bool log_debug:1; // log debugging events? (Must also compile with UTP_DEBUG_LOGGING defined)
185+
186+
private:
187+
void log_impl(utp_socket *socket, char const *fmt, va_list va);
185188
};
186189

187190
#endif //__UTP_INTERNAL_H__

0 commit comments

Comments
 (0)