1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

change from xstrcmp to xstrncmp

This commit is contained in:
Harald Barth 2022-10-19 11:10:37 +02:00
parent e8180603ba
commit 9afce0a7df
2 changed files with 13 additions and 12 deletions

View File

@ -1 +1 @@
#define GITHUB_SHA "PORTX-HAL-cursense2-202210182141Z"
#define GITHUB_SHA "PORTX-HAL-cursense2-202210190909Z"

View File

@ -63,15 +63,16 @@
WiThrottle * WiThrottle::firstThrottle=NULL;
static uint8_t xstrcmp(const char *s1, const char *s2) {
while(*s1 != '\0' && *s2 != '\0') {
if (*s1 != *s2) return 1;
s1++;
s2++;
}
if (*s1 == '\0' && *s2 == '\0')
static uint8_t xstrncmp(const char *s1, const char *s2, uint8_t n) {
if (n == 0)
return 0;
do {
if (*s1 != *s2++)
return 1;
if (*s1++ == 0)
break;
} while (--n != 0);
return 0;
}
void WiThrottle::findUniqThrottle(int id, char *u) {
@ -81,15 +82,15 @@ void WiThrottle::findUniqThrottle(int id, char *u) {
// search 1, look for clientid match
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle){
if (wt->clientid == id) {
wtmyid = wt;
if (xstrcmp(u, wt->uniq) == 0) // should be most common case
if (xstrncmp(u, wt->uniq, 16) == 0) // should be most common case
return;
wtmyid = wt;
break;
}
}
// search 2, look for string match
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle){
if (xstrcmp(u, wt->uniq) == 0) {
if (xstrncmp(u, wt->uniq, 16) == 0) {
wtmyuniq = wt;
break;
}