From 731a79b2247eecc9a773e2845ef57f3bf96f9765 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 4 Aug 2023 22:19:54 +0100 Subject: [PATCH] Fix truncation of dump_command_log console command output --- src/command.cpp | 10 ++++++---- src/command_func.h | 2 +- src/console_cmds.cpp | 8 +++++--- src/crashlog.cpp | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 895c2e5007..a323f5047f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -686,7 +686,7 @@ static void DumpSubCommandLogEntry(char *&buffer, const char *last, const Comman } } -static void DumpSubCommandLog(char *&buffer, const char *last, const CommandLog &cmd_log, const unsigned int count) +static void DumpSubCommandLog(char *&buffer, const char *last, const CommandLog &cmd_log, const unsigned int count, std::function &flush) { unsigned int log_index = cmd_log.next; for (unsigned int i = 0 ; i < count; i++) { @@ -702,20 +702,22 @@ static void DumpSubCommandLog(char *&buffer, const char *last, const CommandLog DumpSubCommandLogEntry(buffer, last, entry); buffer += seprintf(buffer, last, "\n"); + if (flush) buffer = flush(buffer); } } -char *DumpCommandLog(char *buffer, const char *last) +char *DumpCommandLog(char *buffer, const char *last, std::function flush) { const unsigned int count = std::min(_command_log.count, 256); buffer += seprintf(buffer, last, "Command Log:\n Showing most recent %u of %u commands\n", count, _command_log.count); - DumpSubCommandLog(buffer, last, _command_log, count); + DumpSubCommandLog(buffer, last, _command_log, count, flush); if (_command_log_aux.count > 0) { const unsigned int aux_count = std::min(_command_log_aux.count, 32); buffer += seprintf(buffer, last, "\n Showing most recent %u of %u commands (aux log)\n", aux_count, _command_log_aux.count); - DumpSubCommandLog(buffer, last, _command_log_aux, aux_count); + DumpSubCommandLog(buffer, last, _command_log_aux, aux_count, flush); } + if (flush) buffer = flush(buffer); return buffer; } diff --git a/src/command_func.h b/src/command_func.h index 2c9fd8b314..c3a4984833 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -83,7 +83,7 @@ static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags) } void ClearCommandLog(); -char *DumpCommandLog(char *buffer, const char *last); +char *DumpCommandLog(char *buffer, const char *last, std::function flush); void ExecuteCommandQueue(); void ClearCommandQueue(); diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index a849980da6..6ed3984104 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -2576,9 +2576,11 @@ DEF_CONSOLE_CMD(ConDumpCommandLog) return true; } - char buffer[32768]; - DumpCommandLog(buffer, lastof(buffer)); - PrintLineByLine(buffer); + char buffer[2048]; + DumpCommandLog(buffer, lastof(buffer), [&](char *current) -> char * { + PrintLineByLine(buffer); + return buffer; + }); return true; } diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 4a378cb9aa..36b69a32f7 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -508,7 +508,7 @@ char *CrashLog::LogRecentNews(char *buffer, const char *last) const */ char *CrashLog::LogCommandLog(char *buffer, const char *last) const { - buffer = DumpCommandLog(buffer, last); + buffer = DumpCommandLog(buffer, last, nullptr); buffer += seprintf(buffer, last, "\n"); buffer = DumpSpecialEventsLog(buffer, last); buffer += seprintf(buffer, last, "\n");