From 671ba9915e8935c368059a24f377cd7b0007cd0f Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 29 May 2018 08:59:49 +0000 Subject: [PATCH] Fix comparison and a warning Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4107 --- src/hardware/serialport/libserial.cpp | 9 ++++++--- src/hardware/serialport/softmodem.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hardware/serialport/libserial.cpp b/src/hardware/serialport/libserial.cpp index aa5e9168..761049d4 100644 --- a/src/hardware/serialport/libserial.cpp +++ b/src/hardware/serialport/libserial.cpp @@ -151,10 +151,13 @@ void SERIAL_getErrorString(char* buffer, int length) { sysmsg_offset = strlen(err2text); memcpy(buffer,err2text,sysmsg_offset); } - - if((length - sysmsg_offset - strlen((const char*)sysmessagebuffer)) >= 0) + + // Go for length > so there will be bytes left afterwards. + // (which are 0 due to memset, thus the buffer is 0 terminated + if ( length > (sysmsg_offset + strlen((const char*)sysmessagebuffer)) ) { memcpy(buffer + sysmsg_offset, sysmessagebuffer, - strlen((const char*)sysmessagebuffer)); + strlen((const char*)sysmessagebuffer)); + } LocalFree(sysmessagebuffer); } diff --git a/src/hardware/serialport/softmodem.cpp b/src/hardware/serialport/softmodem.cpp index 0cd87105..58531d59 100644 --- a/src/hardware/serialport/softmodem.cpp +++ b/src/hardware/serialport/softmodem.cpp @@ -270,7 +270,7 @@ void CSerialModem::EnterIdleState(void){ } // get rid of everything if(serversocket) { - while(waitingclientsocket=serversocket->Accept()) + while( (waitingclientsocket=serversocket->Accept()) ) delete waitingclientsocket; } else if (listenport) {