From f74067c2b018b37e14e76ce89bd1f54eb07b0bcb Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Wed, 19 Jun 2019 08:11:01 +0000 Subject: [PATCH] Use size_t when dealing with strings and strlen. (Alexandre) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4232 --- src/hardware/serialport/libserial.cpp | 16 ++++++++-------- src/hardware/serialport/libserial.h | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/hardware/serialport/libserial.cpp b/src/hardware/serialport/libserial.cpp index 35eaddc6..3b0a4520 100644 --- a/src/hardware/serialport/libserial.cpp +++ b/src/hardware/serialport/libserial.cpp @@ -41,7 +41,7 @@ bool SERIAL_open(const char* portname, COMPORT* port) { // open the port in NT object space (recommended by Microsoft) // allows the user to open COM10+ and custom port names. - int len = strlen(portname); + size_t len = strlen(portname); if(len > 240) { SetLastError(ERROR_BUFFER_OVERFLOW); free(cp); @@ -125,7 +125,7 @@ void SERIAL_close(COMPORT port) { free(port); } -void SERIAL_getErrorString(char* buffer, int length) { +void SERIAL_getErrorString(char* buffer, size_t length) { int error = GetLastError(); if(length < 50) return; memset(buffer,0,length); @@ -141,7 +141,7 @@ void SERIAL_getErrorString(char* buffer, int length) { const char* err5text = "The specified port is already in use.\n"; const char* err2text = "The specified port does not exist.\n"; - int sysmsg_offset = 0; + size_t sysmsg_offset = 0; if(error == 5) { sysmsg_offset = strlen(err5text); @@ -287,7 +287,7 @@ bool SERIAL_open(const char* portname, COMPORT* port) { cp->breakstatus=false; - int len = strlen(portname); + size_t len = strlen(portname); if(len > 240) { ///////////////////////////////////SetLastError(ERROR_BUFFER_OVERFLOW); return false; @@ -299,7 +299,7 @@ bool SERIAL_open(const char* portname, COMPORT* port) { if (cp->porthandle < 0) goto cleanup_error; result = tcgetattr(cp->porthandle,&cp->backup); - if (result==-1) goto cleanup_error; + if (result == -1) goto cleanup_error; // get port settings termios termInfo; @@ -334,7 +334,7 @@ void SERIAL_close(COMPORT port) { free(port); } -void SERIAL_getErrorString(char* buffer, int length) { +void SERIAL_getErrorString(char* buffer, size_t length) { int error = errno; if(length < 50) return; memset(buffer,0,length); @@ -344,7 +344,7 @@ void SERIAL_getErrorString(char* buffer, int length) { const char* err5text = "The specified port is already in use.\n"; const char* err2text = "The specified port does not exist.\n"; - int sysmsg_offset = 0; + size_t sysmsg_offset = 0; if(error == EBUSY) { sysmsg_offset = strlen(err5text); @@ -548,7 +548,7 @@ cleanup_error: return false; } -void SERIAL_getErrorString(char* buffer, int length) { +void SERIAL_getErrorString(char* buffer, size_t length) { sprintf(buffer, "TODO: error handling is not fun"); } void SERIAL_close(COMPORT port) { diff --git a/src/hardware/serialport/libserial.h b/src/hardware/serialport/libserial.h index 92077772..e3e5a296 100644 --- a/src/hardware/serialport/libserial.h +++ b/src/hardware/serialport/libserial.h @@ -16,12 +16,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include typedef struct _COMPORT *COMPORT; bool SERIAL_open(const char* portname, COMPORT* port); void SERIAL_close(COMPORT port); -void SERIAL_getErrorString(char* buffer, int length); +void SERIAL_getErrorString(char* buffer, size_t length); #define SERIAL_1STOP 1 #define SERIAL_2STOP 2