fix(analytics): fix errors in parsing options.

This commit is contained in:
Haojun Liao 2024-11-21 15:39:25 +08:00
parent af1c0c98bb
commit ac3081a4a4
1 changed files with 25 additions and 21 deletions

View File

@ -128,15 +128,20 @@ void taosAnalUpdate(int64_t newVer, SHashObj *pHash) {
bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue, int32_t optMaxLen) {
char buf[TSDB_ANALYTIC_ALGO_OPTION_LEN] = {0};
char *pStart = strstr(option, optName);
char *pEnd = strstr(pStart, ANAL_ALGO_SPLIT);
char *pStart = NULL;
char *pEnd = NULL;
if (pStart != NULL) {
pStart = strstr(option, optName);
if (pStart == NULL) {
return false;
}
pEnd = strstr(pStart, ANAL_ALGO_SPLIT);
if (optMaxLen > 0) {
int32_t copyLen = optMaxLen;
int32_t copyLen = 0;
if (pEnd > pStart) {
copyLen = (int32_t)(pEnd - pStart - strlen(optName));
copyLen = MIN(copyLen, optMaxLen);
copyLen = (int32_t)(pEnd - pStart);
copyLen = MIN(copyLen + 1, TSDB_ANALYTIC_ALGO_OPTION_LEN);
tstrncpy(buf, pStart, copyLen);
} else {
int32_t len = MIN(tListLen(buf), strlen(pStart) + 1);
@ -146,12 +151,11 @@ bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue,
char *pRight = strstr(buf, "=") + 1;
strtrim(pRight);
tstrncpy(optValue, pRight, strlen(pRight) + 1);
int32_t vLen = MIN(optMaxLen, strlen(pRight) + 1);
tstrncpy(optValue, pRight, vLen);
}
return true;
} else {
return false;
}
}
bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValue) {