From: Martin Ling Date: Wed, 6 May 2015 15:12:27 +0000 (+0100) Subject: windows: Strip CR/LF from end of system error messages. X-Git-Tag: libserialport-0.1.1~38 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9a0c4bbdbea521433372fec48cee9d43328da268;p=libserialport.git windows: Strip CR/LF from end of system error messages. This fixes bug #585. --- diff --git a/serialport.c b/serialport.c index e4f02fc..aaa6095 100644 --- a/serialport.c +++ b/serialport.c @@ -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));