summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-04-12 22:51:10 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-04-12 22:51:10 +0200
commitc17463bcae75a9f9b7108807745ec7bb2d472514 (patch)
treea089c8858bbc928e4cad61a5a21b867df56d4d9a
parent4ded5ca9280d8538cb4aa8f478021476a5643e5c (diff)
Filter out newlines from error messages on Windows
-rw-r--r--src/dynamic.cpp4
-rw-r--r--src/socketengine.cpp8
-rw-r--r--win/inspircd_win32wrapper.cpp5
3 files changed, 16 insertions, 1 deletions
diff --git a/src/dynamic.cpp b/src/dynamic.cpp
index 1470dff0c..b17f13190 100644
--- a/src/dynamic.cpp
+++ b/src/dynamic.cpp
@@ -101,5 +101,9 @@ void DLLManager::RetrieveLastError()
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errmsg, 100, 0);
SetLastError(ERROR_SUCCESS);
err = errmsg;
+
+ std::string::size_type p;
+ while ((p = err.find_last_of("\r\n")) != std::string::npos)
+ err.erase(p, 1);
}
#endif
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index 8af598b06..4a9a2ef10 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -265,7 +265,13 @@ std::string SocketEngine::LastError()
DWORD dwErrorCode = WSAGetLastError();
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)szErrorString, _countof(szErrorString), NULL) == 0)
sprintf_s(szErrorString, _countof(szErrorString), "Error code: %u", dwErrorCode);
- return szErrorString;
+
+ std::string::size_type p;
+ std::string ret = szErrorString;
+ while ((p = ret.find_last_of("\r\n")) != std::string::npos)
+ ret.erase(p, 1);
+
+ return ret;
#endif
}
diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp
index 048baf38b..7707dea0c 100644
--- a/win/inspircd_win32wrapper.cpp
+++ b/win/inspircd_win32wrapper.cpp
@@ -205,6 +205,11 @@ CWin32Exception::CWin32Exception() : exception()
dwErrorCode = GetLastError();
if( FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)szErrorString, _countof(szErrorString), NULL) == 0 )
sprintf_s(szErrorString, _countof(szErrorString), "Error code: %u", dwErrorCode);
+ for (size_t i = 0; i < _countof(szErrorString); i++)
+ {
+ if ((szErrorString[i] == '\r') || (szErrorString[i] == '\n'))
+ szErrorString[i] = 0;
+ }
}
CWin32Exception::CWin32Exception(const CWin32Exception& other)