From ec4ec2133b59a4b045982cc93d30df88a1e72119 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:01:43 -0800 Subject: [PATCH] fix: logging uninitialized memory (#1658) fixes an issue where the console would halt because we printed a control code which did such --- dNet/AuthPackets.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index 561f78e0..380eb8f0 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -87,6 +87,13 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c server->Send(bitStream, sysAddr, false); } +std::string CleanReceivedString(const std::string& str) { + std::string toReturn = str; + const auto removed = std::ranges::find_if(toReturn, [](char c) { return isprint(c) == 0 && isblank(c) == 0; }); + toReturn.erase(removed, toReturn.end()); + return toReturn; +} + void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) { CINSTREAM_SKIP_HEADER; @@ -111,11 +118,11 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) { LUWString memoryStats(256); inStream.Read(memoryStats); - LOG_DEBUG("Memory Stats [%s]", memoryStats.GetAsString().c_str()); + LOG_DEBUG("Memory Stats [%s]", CleanReceivedString(memoryStats.GetAsString()).c_str()); LUWString videoCard(128); inStream.Read(videoCard); - LOG_DEBUG("VideoCard Info: [%s]", videoCard.GetAsString().c_str()); + LOG_DEBUG("VideoCard Info: [%s]", CleanReceivedString(videoCard.GetAsString()).c_str()); // Processor/CPU info uint32_t numOfProcessors;