Fix unsigned integer comparison bug

This commit is contained in:
Will Hedgecock 2021-12-17 13:14:58 -06:00
parent 4a8d6c8827
commit 9a576ea145
6 changed files with 8 additions and 8 deletions

View File

@ -170,7 +170,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
{
if (wcsstr(locationString, L"Hub"))
hubNumber = _wtoi(wcschr(wcsstr(locationString, L"Hub"), L'#') + 1);
if ((portNumber < 0) && wcsstr(locationString, L"Port"))
if ((portNumber == -1) && wcsstr(locationString, L"Port"))
{
wchar_t *portString = wcschr(wcsstr(locationString, L"Port"), L'#') + 1;
if (portString)
@ -184,11 +184,11 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
}
free(locationString);
}
if (busNumber < 0)
if (busNumber == -1)
busNumber = 0;
if (hubNumber < 0)
if (hubNumber == -1)
hubNumber = 0;
if (portNumber < 0)
if (portNumber == -1)
portNumber = 0;
locationString = (wchar_t*)malloc(32*sizeof(wchar_t));
_snwprintf(locationString, 32, L"%d-%d.%d", busNumber, hubNumber, portNumber);

View File

@ -113,7 +113,7 @@ void getPortsWindows(void)
{
if (wcsstr(locationString, L"Hub"))
hubNumber = _wtoi(wcschr(wcsstr(locationString, L"Hub"), L'#') + 1);
if ((portNumber < 0) && wcsstr(locationString, L"Port"))
if ((portNumber == -1) && wcsstr(locationString, L"Port"))
{
wchar_t *portString = wcschr(wcsstr(locationString, L"Port"), L'#') + 1;
if (portString)
@ -127,11 +127,11 @@ void getPortsWindows(void)
}
free(locationString);
}
if (busNumber < 0)
if (busNumber == -1)
busNumber = 0;
if (hubNumber < 0)
if (hubNumber == -1)
hubNumber = 0;
if (portNumber < 0)
if (portNumber == -1)
portNumber = 0;
locationString = (wchar_t*)malloc(32*sizeof(wchar_t));
_snwprintf(locationString, 32, L"%d-%d.%d", busNumber, hubNumber, portNumber);