From 9a0c4bbdbea521433372fec48cee9d43328da268 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Wed, 6 May 2015 16:12:27 +0100 Subject: [PATCH] windows: Strip CR/LF from end of system error messages. This fixes bug #585. --- serialport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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));