]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Filter out newlines from error messages on Windows
authorAttila Molnar <attilamolnar@hush.com>
Sat, 12 Apr 2014 20:51:10 +0000 (22:51 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 12 Apr 2014 20:51:10 +0000 (22:51 +0200)
src/dynamic.cpp
src/socketengine.cpp
win/inspircd_win32wrapper.cpp

index 1470dff0cae7c0df683b7d4cd0484e2d8694267f..b17f131904a165234fc7b69810af4ecf8daeefba 100644 (file)
@@ -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
index 8af598b069ed6184565810688b416f2823f88810..4a9a2ef10539e1b0c50d5c77fbc02e6aa6b49227 100644 (file)
@@ -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
 }
 
index 048baf38be99a7ea2b9dcc8ed5dfd5745637b99e..7707dea0c1b0d58799dff4b686d120588711172e 100644 (file)
@@ -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)