fixed read problem on Windows 10, use secure versions of strncpy, fix bug in set_break

svn path=/trunk/externals/iem/comport/; revision=17565
This commit is contained in:
Martin Peach 2015-12-07 21:30:23 +01:00 committed by IOhannes m zmölnig
parent 052c5e675f
commit a2be44ba74

View file

@ -419,7 +419,7 @@ static int set_break(t_comport *x, int on)
if (fd == INVALID_HANDLE_VALUE) return -1;
status = EscapeCommFunction(fd, dwFunc);
if (status != 0) return nr;
if (status != 0) return on;
return -1; /* didn't work, GetLastError tells why */
}
@ -1083,6 +1083,7 @@ static void comport_tick(t_comport *x)
/*osReader.Pointer = 0; seems MinGW doesn't knoow about this one */
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if(ReadFile(x->comhandle, x->x_inbuf, x->x_inbuf_len, &dwRead, &osReader))
//if (ReadFile(x->comhandle, x->x_inbuf, NULL, &dwRead, &osReader))
{
if(dwRead > 0)
{
@ -1095,8 +1096,27 @@ static void comport_tick(t_comport *x)
else
{
whicherr = GetLastError();
if (whicherr != ERROR_IO_PENDING)
err = -1;
if (whicherr == ERROR_IO_PENDING)
{
//post("iopending\n");
if (GetOverlappedResult(x->comhandle, &osReader, &dwRead, FALSE)) // don't wait
{
//post("dwRead %ld\n", dwRead);
if (dwRead > 0)
{
for (dwX = 0; dwX < dwRead;dwX++)
{
outlet_float(x->x_data_outlet, (t_float)x->x_inbuf[dwX]);
}
}
}
else
{
whicherr = GetLastError();
if (whicherr != ERROR_IO_PENDING) err = -1;
}
}
else err = -1;
}
CloseHandle(osReader.hEvent);
#else
@ -1303,7 +1323,11 @@ allows COM port numbers to be specified. */
/* Open the Comport for RD and WR and get a handle */
/* this line should use a real serial device */
strncpy(test.serial_device_prefix, serial_device_prefix, strlen(serial_device_prefix)+1);
#ifdef _MSC_VER
strncpy_s(test.serial_device_prefix, strlen(serial_device_prefix) + 1, serial_device_prefix, strlen(serial_device_prefix) + 1);
#else
strncpy(test.serial_device_prefix, serial_device_prefix, strlen(serial_device_prefix) + 1);
#endif
test.baud = fbaud;
test.data_bits = 8; /* default 8 data bits */
test.parity_bit = 0;/* default no parity bit */
@ -1321,7 +1345,11 @@ allows COM port numbers to be specified. */
x = (t_comport *)pd_new(comport_class);
x->comport = test.comport;/* com_num */
strncpy(x->serial_device_prefix,serial_device_prefix,strlen(serial_device_prefix)+1);
#ifdef _MSC_VER
strncpy_s(x->serial_device_prefix, strlen(serial_device_prefix) + 1, serial_device_prefix, strlen(serial_device_prefix) + 1);
#else
strncpy(x->serial_device_prefix, serial_device_prefix, strlen(serial_device_prefix) + 1);
#endif
x->serial_device = test.serial_device; /* we need this so 'help' doesn't crash */
x->baud = test.baud;
@ -2013,7 +2041,7 @@ void comport_setup(void)
null_tv.tv_usec = 0;
#endif /* NOT _WIN32 */
verbose(-1, "comport - PD external for unix/windows\n"
"LGPL 1998-2012, Winfried Ritsch and others (see LICENSE.txt)\n"
"LGPL 1998-2015, Winfried Ritsch and others (see LICENSE.txt)\n"
"Institute for Electronic Music - Graz");
}