From 352da6a268f00447fc55a8a6e7be6929c0aede8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 9 Jul 2008 20:33:50 +0900 Subject: [PATCH] Escape double quotes and slashes when outputing C strings. --- log.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/log.cpp b/log.cpp index f4c7746..0c5a09e 100644 --- a/log.cpp +++ b/log.cpp @@ -69,11 +69,10 @@ static void _ReOpen(void) { NULL); } -static void Write(const char *szText) { +static void Write(const char *sBuffer, DWORD dwBytesToWrite) { if(g_hFile == INVALID_HANDLE_VALUE) return; - DWORD dwBytesToWrite = (DWORD)strlen(szText); DWORD dwBytesWritten = 0; while (dwBytesWritten < dwBytesToWrite) { @@ -85,7 +84,7 @@ static void Write(const char *szText) { overlapped.OffsetHigh = 0xffffffff; if(WriteFile(g_hFile, - szText + dwBytesWritten, + sBuffer + dwBytesWritten, dwBytesToWrite - dwBytesWritten, &dwBytesWritten, &overlapped) == FALSE) { @@ -96,6 +95,10 @@ static void Write(const char *szText) { } } +static void Write(const char *szText) { + Write(szText, (DWORD)strlen(szText)); +} + void Open(const TCHAR *szName) { _Open(szName, TEXT("xml")); Write(""); @@ -227,7 +230,11 @@ void DumpString(const char *str) { Log::Text("\""); unsigned char c; while((c = *p++) != 0) { - if(c >= 0x20 && c <= 0x7e) + if(c == '\"') + Text("\\\""); + else if(c == '\\') + Text("\\\\"); + else if(c >= 0x20 && c <= 0x7e) TextChar(c); else if(c == '\t') Text("\\t"); -- 2.43.0