diff --git a/Source/dvlnet/base_protocol.h b/Source/dvlnet/base_protocol.h index 9b37403aa25..8f2d8c1474d 100644 --- a/Source/dvlnet/base_protocol.h +++ b/Source/dvlnet/base_protocol.h @@ -369,11 +369,16 @@ tl::expected base_protocol

::recv_decrypted(packet &pkt, en return {}; std::vector playerNames; for (size_t i = 0; i < Players.size(); i++) { - std::string playerName; - const char *playerNamePointer = reinterpret_cast(infoBuffer.data() + sizeof(GameData) + (i * PlayerNameLength)); - playerName.append(playerNamePointer, strnlen(playerNamePointer, PlayerNameLength)); - if (!playerName.empty()) - playerNames.push_back(playerName); + std::string_view playerNameBuffer { + reinterpret_cast(infoBuffer.data() + sizeof(GameData) + (i * PlayerNameLength)), + PlayerNameLength + }; + if (const size_t nullPos = playerNameBuffer.find('\0'); nullPos != std::string_view::npos) { + playerNameBuffer.remove_suffix(playerNameBuffer.size() - nullPos); + } + if (!playerNameBuffer.empty()) { + playerNames.emplace_back(playerNameBuffer); + } } std::string gameName; size_t gameNameSize = infoBuffer.size() - neededSize;