From 9afce0a7dfeceabe0dcfaf15f5c5c28e4caecc27 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 19 Oct 2022 11:10:37 +0200 Subject: [PATCH] change from xstrcmp to xstrncmp --- GITHUB_SHA.h | 2 +- WiThrottle.cpp | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 3e04613..3e9fb5a 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "PORTX-HAL-cursense2-202210182141Z" +#define GITHUB_SHA "PORTX-HAL-cursense2-202210190909Z" diff --git a/WiThrottle.cpp b/WiThrottle.cpp index d54c650..3df56db 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -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; - return 1; + 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; }