enh:[TD-31088] Handling return value of tcompare.c
This commit is contained in:
parent
3f2239ef03
commit
90be5914f7
|
@ -56,8 +56,8 @@
|
||||||
|
|
||||||
class constantTest {
|
class constantTest {
|
||||||
public:
|
public:
|
||||||
constantTest() { InitRegexCache(); }
|
constantTest() { (void)InitRegexCache(); }
|
||||||
~constantTest() { DestroyRegexCache(); }
|
~constantTest() { (void)DestroyRegexCache(); }
|
||||||
};
|
};
|
||||||
static constantTest test;
|
static constantTest test;
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -1219,7 +1219,7 @@ static RegexCache sRegexCache;
|
||||||
#define REGEX_CACHE_CLEAR_TIME 30
|
#define REGEX_CACHE_CLEAR_TIME 30
|
||||||
|
|
||||||
static void checkRegexCache(void* param, void* tmrId) {
|
static void checkRegexCache(void* param, void* tmrId) {
|
||||||
taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
(void)taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
||||||
if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
|
if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1230,7 +1230,7 @@ static void checkRegexCache(void* param, void* tmrId) {
|
||||||
if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
|
if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char* key = (char*)taosHashGetKey(ppUsingRegex, &len);
|
char* key = (char*)taosHashGetKey(ppUsingRegex, &len);
|
||||||
taosHashRemove(sRegexCache.regexHash, key, len);
|
(void)taosHashRemove(sRegexCache.regexHash, key, len);
|
||||||
}
|
}
|
||||||
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
|
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
|
||||||
}
|
}
|
||||||
|
@ -1267,7 +1267,7 @@ int32_t InitRegexCache() {
|
||||||
|
|
||||||
void DestroyRegexCache(){
|
void DestroyRegexCache(){
|
||||||
uInfo("[regex cache] destory regex cache");
|
uInfo("[regex cache] destory regex cache");
|
||||||
taosTmrStopA(&sRegexCache.timer);
|
(void)taosTmrStopA(&sRegexCache.timer);
|
||||||
taosHashCleanup(sRegexCache.regexHash);
|
taosHashCleanup(sRegexCache.regexHash);
|
||||||
taosTmrCleanUp(sRegexCache.regexCacheTmr);
|
taosTmrCleanUp(sRegexCache.regexCacheTmr);
|
||||||
}
|
}
|
||||||
|
@ -1364,12 +1364,23 @@ static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
|
||||||
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight) {
|
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight) {
|
||||||
size_t sz = varDataLen(pRight);
|
size_t sz = varDataLen(pRight);
|
||||||
char *pattern = taosMemoryMalloc(sz + 1);
|
char *pattern = taosMemoryMalloc(sz + 1);
|
||||||
memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
|
if (NULL == pattern) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
|
||||||
pattern[sz] = 0;
|
pattern[sz] = 0;
|
||||||
|
|
||||||
sz = varDataLen(pLeft);
|
sz = varDataLen(pLeft);
|
||||||
char *str = taosMemoryMalloc(sz + 1);
|
char *str = taosMemoryMalloc(sz + 1);
|
||||||
memcpy(str, varDataVal(pLeft), sz);
|
if (NULL == str) {
|
||||||
|
taosMemoryFree(pattern);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)memcpy(str, varDataVal(pLeft), sz);
|
||||||
str[sz] = 0;
|
str[sz] = 0;
|
||||||
|
|
||||||
int32_t ret = doExecRegexMatch(str, pattern);
|
int32_t ret = doExecRegexMatch(str, pattern);
|
||||||
|
@ -1383,23 +1394,32 @@ int32_t comparestrRegexMatch(const void *pLeft, const void *pRight) {
|
||||||
int32_t comparewcsRegexMatch(const void *pString, const void *pPattern) {
|
int32_t comparewcsRegexMatch(const void *pString, const void *pPattern) {
|
||||||
size_t len = varDataLen(pPattern);
|
size_t len = varDataLen(pPattern);
|
||||||
char *pattern = taosMemoryMalloc(len + 1);
|
char *pattern = taosMemoryMalloc(len + 1);
|
||||||
|
if (NULL == pattern) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pPattern), len, pattern);
|
int convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pPattern), len, pattern);
|
||||||
if (convertLen < 0) {
|
if (convertLen < 0) {
|
||||||
taosMemoryFree(pattern);
|
taosMemoryFree(pattern);
|
||||||
return TSDB_CODE_APP_ERROR;
|
return (terrno = TSDB_CODE_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern[convertLen] = 0;
|
pattern[convertLen] = 0;
|
||||||
|
|
||||||
len = varDataLen(pString);
|
len = varDataLen(pString);
|
||||||
char *str = taosMemoryMalloc(len + 1);
|
char *str = taosMemoryMalloc(len + 1);
|
||||||
|
if (NULL == str) {
|
||||||
|
taosMemoryFree(pattern);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pString), len, str);
|
convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pString), len, str);
|
||||||
if (convertLen < 0) {
|
if (convertLen < 0) {
|
||||||
taosMemoryFree(str);
|
taosMemoryFree(str);
|
||||||
taosMemoryFree(pattern);
|
taosMemoryFree(pattern);
|
||||||
|
return (terrno = TSDB_CODE_APP_ERROR);
|
||||||
return TSDB_CODE_APP_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str[convertLen] = 0;
|
str[convertLen] = 0;
|
||||||
|
|
Loading…
Reference in New Issue