diff --git a/src/Common/Logging.h b/src/Common/Logging.h index d2d273a2b..546ad318e 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -67,6 +67,19 @@ extern thread_local const DWORD _CurrentThreadId; // TODO : Use Boost.Format http://www.boost.org/doc/libs/1_53_0/libs/format/index.html extern thread_local std::string _logPrefix; +// Data sanitization functions + +// Default sanitization functions simply returns the given argument +template +inline T _log_sanitize(T arg) { return arg; } + +// Sanitize C-style strings by converting NULL to "" to prevent null dereference +inline const char * _log_sanitize(const char *arg) { return (NULL == arg) ? "" : arg; } +inline const wchar_t * _log_sanitize(const wchar_t *arg) { return (NULL == arg) ? L"" : arg; } + +// Convert BOOLs to strings properly +inline const char * _log_sanitize(BOOL value) { return value ? "TRUE" : "FALSE"; } + #ifdef _DEBUG_TRACE #define LOG_FUNC_BEGIN \ do { if(g_bPrintfOn) { \ @@ -80,11 +93,7 @@ extern thread_local std::string _logPrefix; // LOG_FUNC_ARG_OUT writes output via all available ostream << operator overloads, adding detail where possible #define LOG_FUNC_ARG(arg) \ - msg << "\n " << std::setw(26) << std::left << std::setfill(' ') << #arg" : " << arg; - - // LOG_FUNC_ARG_STR writes a pointer-based string argument, rendering nulls as - #define LOG_FUNC_ARG_STR(arg) \ - msg << "\n " << std::setw(26) << std::left << std::setfill(' ') << #arg" : " << (arg == NULL ? "" : arg); + msg << "\n " << std::setw(26) << std::left << std::setfill(' ') << #arg" : " << _log_sanitize(arg); // LOG_FUNC_ARG_OUT prevents expansion of types, by only rendering as a pointer #define LOG_FUNC_ARG_OUT(arg) \ diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index 669ad99b5..2991fb866 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -815,7 +815,7 @@ DWORD WINAPI XTL::EmuXLaunchNewImage ) { LOG_FUNC_BEGIN - LOG_FUNC_ARG_STR(lpTitlePath) + LOG_FUNC_ARG(lpTitlePath) LOG_FUNC_ARG(pLaunchData) LOG_FUNC_END;