From 62334dd32ae3b1e86c3bc085e4918d0051344dd4 Mon Sep 17 00:00:00 2001 From: narzoul Date: Thu, 24 Mar 2016 22:57:45 +0100 Subject: [PATCH] Handle null pointers when logging strings --- DDrawCompat/DDrawLog.cpp | 20 ++++++++++++++++++++ DDrawCompat/DDrawLog.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/DDrawCompat/DDrawLog.cpp b/DDrawCompat/DDrawLog.cpp index c38ca8b..b9cdce2 100644 --- a/DDrawCompat/DDrawLog.cpp +++ b/DDrawCompat/DDrawLog.cpp @@ -16,8 +16,28 @@ namespace } } +std::ostream& operator<<(std::ostream& os, const char* str) +{ + if (!str) + { + return os << "null"; + } + + return os.write(str, strlen(str)); +} + +std::ostream& operator<<(std::ostream& os, const unsigned char* data) +{ + return os << static_cast(data); +} + std::ostream& operator<<(std::ostream& os, const WCHAR* wstr) { + if (!wstr) + { + return os << "null"; + } + CStringA str(wstr); return os << '"' << static_cast(str) << '"'; } diff --git a/DDrawCompat/DDrawLog.h b/DDrawCompat/DDrawLog.h index cd6a533..b1791d7 100644 --- a/DDrawCompat/DDrawLog.h +++ b/DDrawCompat/DDrawLog.h @@ -14,6 +14,8 @@ isAlreadyLogged##__LINE__ = true; \ } +std::ostream& operator<<(std::ostream& os, const char* str); +std::ostream& operator<<(std::ostream& os, const unsigned char* data); std::ostream& operator<<(std::ostream& os, const WCHAR* wstr); std::ostream& operator<<(std::ostream& os, const RECT& rect); std::ostream& operator<<(std::ostream& os, HDC__& dc);