]> sigrok.org Git - libserialport.git/commitdiff
windows: Strip CR/LF from end of system error messages.
authorMartin Ling <redacted>
Wed, 6 May 2015 15:12:27 +0000 (16:12 +0100)
committerUwe Hermann <redacted>
Wed, 27 May 2015 09:08:30 +0000 (11:08 +0200)
This fixes bug #585.

serialport.c

index e4f02fc58dde6d1cde27f5863eff49dae0f326e2..aaa609545b20675343b7445fd2e0ccc9716d4b2b 100644 (file)
@@ -2287,10 +2287,10 @@ SP_API char *sp_last_error_message(void)
        TRACE_VOID();
 
 #ifdef _WIN32
-       LPVOID message;
+       TCHAR *message;
        DWORD error = GetLastError();
 
-       FormatMessage(
+       DWORD length = FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -2300,6 +2300,9 @@ SP_API char *sp_last_error_message(void)
                (LPTSTR) &message,
                0, NULL );
 
+       if (length >= 2 && message[length - 2] == '\r')
+               message[length - 2] = '\0';
+
        RETURN_STRING(message);
 #else
        RETURN_STRING(strerror(errno));