Skip to content

refactor: optimize JSON handling, fix pointer safety, and improve overall stability - #15

Open
lozatto wants to merge 14 commits into
SmileYzn:mainfrom
lozatto:main
Open

refactor: optimize JSON handling, fix pointer safety, and improve overall stability#15
lozatto wants to merge 14 commits into
SmileYzn:mainfrom
lozatto:main

Conversation

@lozatto

@lozatto lozatto commented May 15, 2026

Copy link
Copy Markdown
Contributor

This PR introduces several stability improvements, memory optimizations, and crash preventions across the LogApi module. The main focus was to replace pass-by-value with constant references for complex JSON objects, prevent potential crashes from unvalidated engine strings/pointers, and fix an issue with malformed UTF-8 data serialization.

🛠️ Key Changes

  • Performance & Memory Optimization:

  • Changed nlohmann::ordered_json parameters from pass-by-value to pass-by-const-reference (const nlohmann::ordered_json&) across multiple functions (SendEvent, EventResult, ClientPrint, etc.) to eliminate redundant deep copies.

  • Crash & Exploit Prevention:

  • Added nlohmann::ordered_json::error_handler_t::replace during Event.dump() serialization to gracefully handle and replace invalid UTF-8 characters, avoiding potential server crashes.

  • Wrapped critical engine interactions and string conversions inside try-catch blocks (std::exception) to catch generic failures beyond just JSON parse errors.

  • Added strict null-pointer and validation checks for game engine entities and strings (pvPrivateData, net_address, hostname, mapname).

  • Bug Fixes & Refactoring:

  • Fixed a bug in CLogPlayer::GetPlayerJson by copying the rawAuth engine pointer immediately into a std::string, preventing it from being invalidated by subsequent engine calls.

  • Improved buffer safety in menu handling (LogMenu.cpp) by enforcing explicit limits (MAX_BUFFER_MENU) and manual null-termination.

  • Tuned Makefile flags: added -fno-strict-aliasing and removed -static-libgcc -static-libstdc++ from the linker to resolve potential binary compatibility issues on Linux.

lozatto added 14 commits May 9, 2026 15:24
…send log events containing invalid UTF-8 characters (commonly found in player names or chat messages with special symbols). By default, the nlohmann/json library throws an unhandled exception when encountering malformed strings during the serialization process.
…o make the LogApi significantly more stable. The crash logs confirmed that the failure occurred during JSON serialization (dump_escaped), typically caused by invalid UTF-8 characters or null pointers.
@lozatto

lozatto commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@SmileYzn , I’m not sure if you had the opportunity to review the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant