Skip to content

Commit 36004c4

Browse files
committed
Log: remove \r and \n from log lines
1 parent 8cf45f1 commit 36004c4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/log.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdio>
44
#include <ctime>
5+
#include <algorithm>
56

67
using namespace modloader;
78

@@ -18,7 +19,11 @@ const char *modloader_log_level_str(modloader_log_level level) {
1819

1920
void modloader_vlog(modloader_log_level level, const char *tag, const char *format, va_list args) {
2021
char buffer[4096];
21-
vsnprintf(buffer, sizeof(buffer), format, args);
22+
int len = vsnprintf(buffer, sizeof(buffer), format, args);
23+
if (len > sizeof(buffer))
24+
len = sizeof(buffer);
25+
while (len > 0 && (buffer[len - 1] == '\r' || buffer[len - 1] == '\n'))
26+
buffer[--len] = '\0';
2227

2328
char tbuf[128];
2429
tbuf[0] = '\0';

0 commit comments

Comments
 (0)