Ensure all data structures are properly initialized
This commit is contained in:
parent
f06b03f186
commit
155ae7940c
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Android.c
|
||||
*
|
||||
* Created on: Mar 13, 2015
|
||||
* Last Updated on: Nov 07, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -188,7 +188,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
{
|
||||
if (serialPortFD <= 0)
|
||||
return JNI_FALSE;
|
||||
struct serial_struct serInfo;
|
||||
struct serial_struct serInfo = {0};
|
||||
struct termios options = {0};
|
||||
|
||||
// Get port parameters from Java class
|
||||
|
@ -267,13 +267,13 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
setBaudRate(serialPortFD, baudRate);
|
||||
|
||||
// Attempt to set the requested RS-485 mode
|
||||
struct serial_rs485 rs485Conf;
|
||||
struct serial_rs485 rs485Conf = {0};
|
||||
if (ioctl(serialPortFD, TIOCGRS485, &rs485Conf) == 0)
|
||||
{
|
||||
if (rs485ModeEnabled)
|
||||
rs485Conf.flags |= SER_RS485_ENABLED;
|
||||
rs485Conf.flags |= SER_RS485_ENABLED; // Set these too? SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND
|
||||
else
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED;
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED; // Clear these too? &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND);
|
||||
rs485Conf.delay_rts_before_send = rs485DelayBefore;
|
||||
rs485Conf.delay_rts_after_send = rs485DelayAfter;
|
||||
ioctl(serialPortFD, TIOCSRS485, &rs485Conf);
|
||||
|
@ -424,7 +424,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
|||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_FALSE);
|
||||
|
||||
// Force the port to enter non-blocking mode to ensure that any current reads return
|
||||
struct termios options;
|
||||
struct termios options = {0};
|
||||
ioctl(serialPortFD, TCGETS, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
flags |= O_NONBLOCK;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Posix.c
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: Nov 08, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -355,7 +355,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
|
||||
// Attempt to set the transmit buffer size and any necessary custom baud rates
|
||||
#if defined(__linux__)
|
||||
struct serial_struct serInfo;
|
||||
struct serial_struct serInfo = {0};
|
||||
if (ioctl(serialPortFD, TIOCGSERIAL, &serInfo) == 0)
|
||||
{
|
||||
serInfo.xmit_fifo_size = sendDeviceQueueSize;
|
||||
|
@ -370,13 +370,13 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
|
||||
// Attempt to set the requested RS-485 mode
|
||||
#if defined(__linux__)
|
||||
struct serial_rs485 rs485Conf;
|
||||
struct serial_rs485 rs485Conf = {0};
|
||||
if (ioctl(serialPortFD, TIOCGRS485, &rs485Conf) == 0)
|
||||
{
|
||||
if (rs485ModeEnabled)
|
||||
rs485Conf.flags |= SER_RS485_ENABLED;
|
||||
rs485Conf.flags |= SER_RS485_ENABLED; // Set these too? SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND
|
||||
else
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED;
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED; // Clear these too? &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND);
|
||||
rs485Conf.delay_rts_before_send = rs485DelayBefore;
|
||||
rs485Conf.delay_rts_after_send = rs485DelayAfter;
|
||||
ioctl(serialPortFD, TIOCSRS485, &rs485Conf);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Windows.c
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: Nov 07, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -408,7 +408,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return JNI_FALSE;
|
||||
DCB dcbSerialParams = {0};
|
||||
DCB dcbSerialParams{};
|
||||
dcbSerialParams.DCBlength = sizeof(DCB);
|
||||
|
||||
// Get port parameters from Java class
|
||||
|
@ -476,7 +476,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return JNI_FALSE;
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
int timeoutMode = env->GetIntField(obj, timeoutModeField);
|
||||
DWORD readTimeout = (DWORD)env->GetIntField(obj, readTimeoutField);
|
||||
DWORD writeTimeout = (DWORD)env->GetIntField(obj, writeTimeoutField);
|
||||
|
@ -537,7 +537,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
|||
// Change read timeouts if we are monitoring data received
|
||||
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
||||
{
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
timeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutConstant = 1000;
|
||||
|
@ -557,7 +557,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
@ -607,7 +607,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
|||
PurgeComm(serialPortHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR);
|
||||
|
||||
// Force the port to enter non-blocking mode to ensure that any current reads return
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
timeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
|
@ -689,7 +689,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_readBytes(JNIEnv
|
|||
}
|
||||
|
||||
// Create an asynchronous result structure
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
@ -751,7 +751,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_writeBytes(JNIEn
|
|||
}
|
||||
|
||||
// Create an asynchronous result structure
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue