diff --git a/include/common/ttime.h b/include/common/ttime.h index 2d40bd93a6..cec5b15761 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -117,7 +117,7 @@ int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t pr int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, char* errMsg, int32_t errMsgLen); -void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen); +int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen); int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr); /// @brief get offset seconds from zero timezone to input timezone diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 4fca564804..d3207a1912 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -96,8 +96,6 @@ char* forwardToTimeStringEnd(char* str) { } int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t i = 0; int64_t fraction = 0; @@ -147,8 +145,6 @@ int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFractio } int32_t parseTimezone(char* str, int64_t* tzOffset) { - int32_t code = TSDB_CODE_SUCCESS; - int64_t hour = 0; int32_t i = 0; @@ -224,8 +220,6 @@ int32_t offsetOfTimezone(char* tzStr, int64_t* offset) { * 2013-04-12T15:52:01.123+0800 */ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) { - int32_t code = TSDB_CODE_SUCCESS; - int64_t factor = TSDB_TICK_PER_SECOND(timePrec); int64_t tzOffset = 0; @@ -315,8 +309,6 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) { } int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) { - int32_t code = TSDB_CODE_SUCCESS; - *utime = 0; struct tm tm = {0}; @@ -358,8 +350,6 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP } int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) { - int32_t code = TSDB_CODE_SUCCESS; - *utime = 0; struct tm tm = {0}; tm.tm_isdst = -1; @@ -484,8 +474,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre // !!!!notice: double lose precison if time is too large, for example: 1626006833631000000*1.0 = double = // 1626006833631000064 int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes) { - int32_t code = TSDB_CODE_SUCCESS; - if (fromPrecision != TSDB_TIME_PRECISION_MILLI && fromPrecision != TSDB_TIME_PRECISION_MICRO && fromPrecision != TSDB_TIME_PRECISION_NANO) { TAOS_RETURN(TSDB_CODE_INVALID_PARA); @@ -559,13 +547,14 @@ int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char } int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t charLen = varDataLen(inputData); char* newColData; if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY) { newColData = taosMemoryCalloc(1, charLen + 1); - memcpy(newColData, varDataVal(inputData), charLen); + if (NULL == newColData) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + (void)memcpy(newColData, varDataVal(inputData), charLen); int32_t ret = taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, tsDaylight); if (ret != TSDB_CODE_SUCCESS) { taosMemoryFree(newColData); @@ -574,6 +563,9 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec taosMemoryFree(newColData); } else if (type == TSDB_DATA_TYPE_NCHAR) { newColData = taosMemoryCalloc(1, charLen + TSDB_NCHAR_SIZE); + if (NULL == newColData) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } int len = taosUcs4ToMbs((TdUcs4*)varDataVal(inputData), charLen, newColData); if (len < 0) { taosMemoryFree(newColData); @@ -593,8 +585,6 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec } int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { - int32_t code = TSDB_CODE_SUCCESS; - switch (unit) { case 's': if (val > INT64_MAX / MILLISECOND_PER_SECOND) { @@ -658,8 +648,6 @@ int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecisi */ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* duration, char* unit, int32_t timePrecision) { - int32_t code = TSDB_CODE_SUCCESS; - errno = 0; char* endPtr = NULL; @@ -680,8 +668,6 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision, bool negativeAllow) { - int32_t code = TSDB_CODE_SUCCESS; - errno = 0; /* get the basic numeric value */ @@ -718,7 +704,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { struct tm tm; time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); - taosLocalTime(&tt, &tm, NULL); + (void)taosLocalTime(&tt, &tm, NULL); int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)numOfMonth; tm.tm_year = mon / 12; tm.tm_mon = mon % 12; @@ -779,11 +765,11 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva struct tm tm; time_t t = (time_t)skey; - taosLocalTime(&t, &tm, NULL); + (void)taosLocalTime(&t, &tm, NULL); int32_t smon = tm.tm_year * 12 + tm.tm_mon; t = (time_t)ekey; - taosLocalTime(&t, &tm, NULL); + (void)taosLocalTime(&t, &tm, NULL); int32_t emon = tm.tm_year * 12 + tm.tm_mon; if (unit == 'y') { @@ -808,7 +794,7 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { start /= (int64_t)(TSDB_TICK_PER_SECOND(precision)); struct tm tm; time_t tt = (time_t)start; - taosLocalTime(&tt, &tm, NULL); + (void)taosLocalTime(&tt, &tm, NULL); tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 0; @@ -978,8 +964,6 @@ const char* fmtts(int64_t ts) { } int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) { - int32_t code = TSDB_CODE_SUCCESS; - char ts[40] = {0}; struct tm ptm; @@ -1018,7 +1002,7 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio TAOS_RETURN(TSDB_CODE_INVALID_PARA); } - if (taosLocalTime(", &ptm, buf) == NULL) { + if (NULL == taosLocalTime(", &ptm, buf)) { TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); } int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm); @@ -1032,7 +1016,9 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) { tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]); time_t t = ts / TICK_PER_SECOND[precision]; - taosLocalTime(&t, &tm->tm, NULL); + if (NULL == taosLocalTime(&t, &tm->tm, NULL)) { + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + } return TSDB_CODE_SUCCESS; } @@ -1344,7 +1330,7 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int TSFormatNode* format = taosArrayGet(formats, i); if (format->type != TS_FORMAT_NODE_TYPE_KEYWORD) { if (s - start + format->len + 1 > outLen) break; - strncpy(s, format->c, format->len); + (void)strncpy(s, format->c, format->len); s += format->len; continue; } @@ -1353,37 +1339,37 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int switch (format->key->id) { case TSFKW_AM: case TSFKW_PM: - sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM"); + (void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM"); s += 2; break; case TSFKW_A_M: case TSFKW_P_M: - sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M."); + (void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M."); s += 4; break; case TSFKW_am: case TSFKW_pm: - sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am"); + (void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am"); s += 2; break; case TSFKW_a_m: case TSFKW_p_m: - sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m."); + (void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m."); s += 4; break; case TSFKW_DDD: #ifdef WINDOWS return TSDB_CODE_FUNC_TO_CHAR_NOT_SUPPORTED; #endif - sprintf(s, "%03d", tm->tm.tm_yday + 1); + (void)sprintf(s, "%03d", tm->tm.tm_yday + 1); s += strlen(s); break; case TSFKW_DD: - sprintf(s, "%02d", tm->tm.tm_mday); + (void)sprintf(s, "%02d", tm->tm.tm_mday); s += 2; break; case TSFKW_D: - sprintf(s, "%d", tm->tm.tm_wday + 1); + (void)sprintf(s, "%d", tm->tm.tm_wday + 1); s += 1; break; case TSFKW_DAY: { @@ -1391,20 +1377,20 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int const char* wd = weekDays[tm->tm.tm_wday]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]); - sprintf(s, "%-9s", buf); + (void)sprintf(s, "%-9s", buf); s += strlen(s); break; } case TSFKW_Day: // Monday, TuesDay... - sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]); + (void)sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]); s += strlen(s); break; case TSFKW_day: { const char* wd = weekDays[tm->tm.tm_wday]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]); - sprintf(s, "%-9s", buf); + (void)sprintf(s, "%-9s", buf); s += strlen(s); break; } @@ -1413,13 +1399,13 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int const char* wd = shortWeekDays[tm->tm.tm_wday]; char buf[8] = {0}; for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]); - sprintf(s, "%3s", buf); + (void)sprintf(s, "%3s", buf); s += 3; break; } case TSFKW_Dy: // Mon, Tue - sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]); + (void)sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]); s += 3; break; case TSFKW_dy: { @@ -1427,33 +1413,33 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int const char* wd = shortWeekDays[tm->tm.tm_wday]; char buf[8] = {0}; for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]); - sprintf(s, "%3s", buf); + (void)sprintf(s, "%3s", buf); s += 3; break; } case TSFKW_HH24: - sprintf(s, "%02d", tm->tm.tm_hour); + (void)sprintf(s, "%02d", tm->tm.tm_hour); s += 2; break; case TSFKW_HH: case TSFKW_HH12: // 0 or 12 o'clock in 24H coresponds to 12 o'clock (AM/PM) in 12H - sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12); + (void)sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12); s += 2; break; case TSFKW_MI: - sprintf(s, "%02d", tm->tm.tm_min); + (void)sprintf(s, "%02d", tm->tm.tm_min); s += 2; break; case TSFKW_MM: - sprintf(s, "%02d", tm->tm.tm_mon + 1); + (void)sprintf(s, "%02d", tm->tm.tm_mon + 1); s += 2; break; case TSFKW_MONTH: { const char* mon = fullMonths[tm->tm.tm_mon]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]); - sprintf(s, "%-9s", buf); + (void)sprintf(s, "%-9s", buf); s += strlen(s); break; } @@ -1461,44 +1447,44 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int const char* mon = months[tm->tm.tm_mon]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]); - sprintf(s, "%s", buf); + (void)sprintf(s, "%s", buf); s += strlen(s); break; } case TSFKW_Month: - sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]); + (void)sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]); s += strlen(s); break; case TSFKW_month: { const char* mon = fullMonths[tm->tm.tm_mon]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]); - sprintf(s, "%-9s", buf); + (void)sprintf(s, "%-9s", buf); s += strlen(s); break; } case TSFKW_Mon: - sprintf(s, "%s", months[tm->tm.tm_mon]); + (void)sprintf(s, "%s", months[tm->tm.tm_mon]); s += strlen(s); break; case TSFKW_mon: { const char* mon = months[tm->tm.tm_mon]; char buf[10] = {0}; for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]); - sprintf(s, "%s", buf); + (void)sprintf(s, "%s", buf); s += strlen(s); break; } case TSFKW_SS: - sprintf(s, "%02d", tm->tm.tm_sec); + (void)sprintf(s, "%02d", tm->tm.tm_sec); s += 2; break; case TSFKW_MS: - sprintf(s, "%03" PRId64, tm->fsec / 1000000L); + (void)sprintf(s, "%03" PRId64, tm->fsec / 1000000L); s += 3; break; case TSFKW_US: - sprintf(s, "%06" PRId64, tm->fsec / 1000L); + (void)sprintf(s, "%06" PRId64, tm->fsec / 1000L); s += 6; break; case TSFKW_NS: @@ -1506,23 +1492,23 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int s += 9; break; case TSFKW_TZH: - sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone); + (void)sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone); s += strlen(s); break; case TSFKW_YYYY: - sprintf(s, "%04d", tm->tm.tm_year + 1900); + (void)sprintf(s, "%04d", tm->tm.tm_year + 1900); s += strlen(s); break; case TSFKW_YYY: - sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000); + (void)sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000); s += strlen(s); break; case TSFKW_YY: - sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100); + (void)sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100); s += strlen(s); break; case TSFKW_Y: - sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10); + (void)sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10); s += strlen(s); break; default: @@ -1557,7 +1543,7 @@ static const char* tsFormatStr2Int32(int32_t* dest, const char* str, int32_t len s = last; } else { char buf[16] = {0}; - strncpy(buf, s, len); + (void)strncpy(buf, s, len); int32_t copiedLen = strlen(buf); if (copiedLen < len) { if (!needMoreDigit) { @@ -1936,10 +1922,13 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) { if (!*formats) { *formats = taosArrayInit(8, sizeof(TSFormatNode)); + if (!*formats){ + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } parseTsFormat(format, *formats); } struct STm tm; - taosTs2Tm(ts, precision, &tm); + TAOS_CHECK_RETURN(taosTs2Tm(ts, precision, &tm)); return tm2char(*formats, &tm, out, outLen); } @@ -1949,6 +1938,9 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int int32_t fErrIdx; if (!*formats) { *formats = taosArrayInit(4, sizeof(TSFormatNode)); + if (!*formats) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } parseTsFormat(format, *formats); } int32_t code = char2ts(tsStr, *formats, ts, precision, &sErrPos, &fErrIdx); @@ -1964,16 +1956,24 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int snprintf(errMsg, errMsgLen, "timestamp format not supported"); code = TSDB_CODE_FUNC_TO_TIMESTAMP_FAILED_NOT_SUPPORTED; } - return code; + TAOS_RETURN(code); } -void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) { +int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) { + int32_t code = TSDB_CODE_SUCCESS; + SArray* formats = taosArrayInit(4, sizeof(TSFormatNode)); + if (!formats) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } parseTsFormat(format, formats); struct STm tm; - taosTs2Tm(ts, precision, &tm); - tm2char(formats, &tm, out, outLen); + TAOS_CHECK_GOTO(taosTs2Tm(ts, precision, &tm), NULL, _exit); + TAOS_CHECK_GOTO(tm2char(formats, &tm, out, outLen), NULL, _exit); + +_exit: taosArrayDestroy(formats); + TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr) { @@ -1997,17 +1997,19 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1, #define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97] -static int64_t UNIT_MATRIX[10][11] = {/* ns, us, ms, s, min, h, d, w, month, y*/ - /*ns*/ {1, 1000, 0}, - /*us*/ {1000, 1, 1000, 0}, - /*ms*/ {0, 1000, 1, 1000, 0}, - /*s*/ {0, 0, 1000, 1, 60, 0}, - /*min*/ {0, 0, 0, 60, 1, 60, 0}, - /*h*/ {0, 0, 0, 0, 60, 1, 1, 0}, - /*d*/ {0, 0, 0, 0, 0, 24, 1, 7, 1, 0}, - /*w*/ {0, 0, 0, 0, 0, 0, 7, 1, -1, 0}, - /*mon*/ {0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 0}, - /*y*/ {0, 0, 0, 0, 0, 0, 0, 0, 12, 1, 0}}; +// clang-format off +static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/ + /*ns*/ { 1, 1000, 0}, + /*us*/ {1000, 1, 1000, 0}, + /*ms*/ { 0, 1000, 1, 1000, 0}, + /*s*/ { 0, 0, 1000, 1, 60, 0}, + /*min*/ { 0, 0, 0, 60, 1, 60, 0}, + /*h*/ { 0, 0, 0, 0, 60, 1, 1, 0}, + /*d*/ { 0, 0, 0, 0, 0, 24, 1, 7, 1, 0}, + /*w*/ { 0, 0, 0, 0, 0, 0, 7, 1, -1, 0}, + /*mon*/ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 0}, + /*y*/ { 0, 0, 0, 0, 0, 0, 0, 0, 12, 1, 0}}; +// clang-format on static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, bool checkEq) { diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index 360d1ed31a..b539d6731f 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -465,7 +465,8 @@ TEST(timeTest, timestamp2tm) { void test_ts2char(int64_t ts, const char* format, int32_t precison, const char* expected) { char buf[256] = {0}; - TEST_ts2char(format, ts, precison, buf, 256); + int32_t code = TEST_ts2char(format, ts, precison, buf, 256); + ASSERT_EQ(code, 0); printf("ts: %ld format: %s res: [%s], expected: [%s]\n", ts, format, buf, expected); ASSERT_STREQ(expected, buf); } diff --git a/source/libs/geometry/src/geomFunc.c b/source/libs/geometry/src/geomFunc.c index 601588571e..343e6ec4ce 100644 --- a/source/libs/geometry/src/geomFunc.c +++ b/source/libs/geometry/src/geomFunc.c @@ -21,8 +21,8 @@ #include "sclInt.h" #include "sclvector.h" -typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, - bool swapped, char *res); +typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, + const GEOSGeometry *geom2, bool swapped, char *res); typedef int32_t (*_geomInitCtxFunc_t)(); typedef int32_t (*_geomExecuteOneParamFunc_t)(SColumnInfoData *pInputData, int32_t i, SColumnInfoData *pOutputData); @@ -35,7 +35,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) { int32_t code = TSDB_CODE_FAILED; unsigned char *outputGeom = NULL; - size_t size = 0; + size_t size = 0; code = doMakePoint(x, y, &outputGeom, &size); if (code != TSDB_CODE_SUCCESS) { goto _exit; @@ -47,7 +47,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) { goto _exit; } - memcpy(varDataVal(*output), outputGeom, size); + (void)memcpy(varDataVal(*output), outputGeom, size); varDataSetLen(*output, size); code = TSDB_CODE_SUCCESS; @@ -62,14 +62,14 @@ _exit: int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { int32_t code = TSDB_CODE_FAILED; - if ((varDataLen(input)) == 0) { //empty value + if ((varDataLen(input)) == 0) { // empty value *output = NULL; return TSDB_CODE_SUCCESS; } - char *inputGeom = NULL; + char *inputGeom = NULL; unsigned char *outputGeom = NULL; - size_t size = 0; + size_t size = 0; // make a zero ending string inputGeom = taosMemoryCalloc(1, varDataLen(input) + 1); @@ -77,12 +77,9 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; } - memcpy(inputGeom, varDataVal(input), varDataLen(input)); + (void)memcpy(inputGeom, varDataVal(input), varDataLen(input)); - code = doGeomFromText(inputGeom, &outputGeom, &size); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(doGeomFromText(inputGeom, &outputGeom, &size), NULL, _exit); *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { @@ -90,7 +87,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { goto _exit; } - memcpy(varDataVal(*output), outputGeom, size); + (void)memcpy(varDataVal(*output), outputGeom, size); varDataSetLen(*output, size); code = TSDB_CODE_SUCCESS; @@ -106,16 +103,13 @@ _exit: int32_t doAsTextFunc(unsigned char *input, char **output) { int32_t code = TSDB_CODE_FAILED; - if ((varDataLen(input)) == 0) { //empty value + if ((varDataLen(input)) == 0) { // empty value *output = NULL; return TSDB_CODE_SUCCESS; } char *outputWKT = NULL; - code = doAsText(varDataVal(input), varDataLen(input), &outputWKT); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(doAsText(varDataVal(input), varDataLen(input), &outputWKT), NULL, _exit); size_t size = strlen(outputWKT); *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); @@ -124,7 +118,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) { goto _exit; } - memcpy(varDataVal(*output), outputWKT, size); + (void)memcpy(varDataVal(*output), outputWKT, size); varDataSetLen(*output, size); code = TSDB_CODE_SUCCESS; @@ -139,28 +133,17 @@ int32_t executeMakePointFunc(SColumnInfoData *pInputData[], int32_t iLeft, int32 int32_t code = TSDB_CODE_FAILED; _getDoubleValue_fn_t getDoubleValueFn[2]; - getDoubleValueFn[0]= getVectorDoubleValueFn(pInputData[0]->info.type); - getDoubleValueFn[1]= getVectorDoubleValueFn(pInputData[1]->info.type); + getDoubleValueFn[0] = getVectorDoubleValueFn(pInputData[0]->info.type); + getDoubleValueFn[1] = getVectorDoubleValueFn(pInputData[1]->info.type); unsigned char *output = NULL; - double leftRes = 0; - double rightRes = 0; - code = getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes); - if (TSDB_CODE_SUCCESS != code) { - goto _exit; - } - code = getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes); - if (TSDB_CODE_SUCCESS != code) { - goto _exit; - } - code = doMakePointFunc(leftRes, rightRes, &output); - if (TSDB_CODE_SUCCESS != code) { - goto _exit; - } - code = colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL)); - if (TSDB_CODE_SUCCESS != code) { - goto _exit; - } + double leftRes = 0; + double rightRes = 0; + + TAOS_CHECK_GOTO(getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes), NULL, _exit); + TAOS_CHECK_GOTO(getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes), NULL, _exit); + TAOS_CHECK_GOTO(doMakePointFunc(leftRes, rightRes, &output), NULL, _exit); + TAOS_CHECK_GOTO(colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL)), NULL, _exit); _exit: if (output) { @@ -173,14 +156,11 @@ _exit: int32_t executeGeomFromTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoData *pOutputData) { int32_t code = TSDB_CODE_FAILED; - char *input = colDataGetData(pInputData, i); + char *input = colDataGetData(pInputData, i); unsigned char *output = NULL; - code = doGeomFromTextFunc(input, &output); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } - code = colDataSetVal(pOutputData, i, output, (output == NULL)); + TAOS_CHECK_GOTO(doGeomFromTextFunc(input, &output), NULL, _exit); + TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit); _exit: if (output) { @@ -194,13 +174,10 @@ int32_t executeAsTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoDat int32_t code = TSDB_CODE_FAILED; unsigned char *input = colDataGetData(pInputData, i); - char *output = NULL; - code = doAsTextFunc(input, &output); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + char *output = NULL; - code = colDataSetVal(pOutputData, i, output, (output == NULL)); + TAOS_CHECK_GOTO(doAsTextFunc(input, &output), NULL, _exit); + TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit); _exit: if (output) { @@ -211,36 +188,24 @@ _exit: } int32_t executeRelationFunc(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, - const GEOSGeometry *geom2, int32_t i, - bool swapped, SColumnInfoData *pOutputData, + const GEOSGeometry *geom2, int32_t i, bool swapped, SColumnInfoData *pOutputData, _geomDoRelationFunc_t doRelationFn) { - int32_t code = TSDB_CODE_FAILED; char res = 0; - if (!geom1 || !geom2) { //if empty input value + if (!geom1 || !geom2) { // if empty input value res = -1; - code = TSDB_CODE_SUCCESS; - } - else { - code = doRelationFn(geom1, preparedGeom1, geom2, swapped, &res); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + } else { + TAOS_CHECK_RETURN(doRelationFn(geom1, preparedGeom1, geom2, swapped, &res)); } - code = colDataSetVal(pOutputData, i, &res, (res==-1)); - - return code; + return colDataSetVal(pOutputData, i, &res, (res == -1)); } -int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, - _geomInitCtxFunc_t initCtxFn, _geomExecuteOneParamFunc_t executeOneParamFn) { +int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn, + _geomExecuteOneParamFunc_t executeOneParamFn) { int32_t code = TSDB_CODE_FAILED; - code = initCtxFn(); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TAOS_CHECK_RETURN(initCtxFn()); SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; @@ -249,8 +214,7 @@ int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, if (IS_NULL_TYPE(GET_PARAM_TYPE(pInput))) { colDataSetNNULL(pOutputData, 0, pInput->numOfRows); code = TSDB_CODE_SUCCESS; - } - else { + } else { for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataSetNULL(pOutputData, i); @@ -258,44 +222,36 @@ int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, continue; } - code = executeOneParamFn(pInputData, i, pOutputData); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TAOS_CHECK_RETURN(executeOneParamFn(pInputData, i, pOutputData)); } } - return code; + TAOS_RETURN(code); } -int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput, - _geomInitCtxFunc_t initCtxFn, _geomExecuteTwoParamsFunc_t executeTwoParamsFn) { +int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn, + _geomExecuteTwoParamsFunc_t executeTwoParamsFn) { int32_t code = TSDB_CODE_FAILED; - code = initCtxFn(); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TAOS_CHECK_RETURN(initCtxFn()); SColumnInfoData *pInputData[2]; SColumnInfoData *pOutputData = pOutput->columnData; pInputData[0] = pInput[0].columnData; pInputData[1] = pInput[1].columnData; - bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); - bool isConstantLeft = (pInput[0].numOfRows == 1); - bool isConstantRight = (pInput[1].numOfRows == 1); + bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); + bool isConstantLeft = (pInput[0].numOfRows == 1); + bool isConstantRight = (pInput[1].numOfRows == 1); int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); pOutput->numOfRows = numOfRows; - if (hasNullType || // one of operant is NULL type - (isConstantLeft && colDataIsNull_s(pInputData[0], 0)) || // left operand is constant NULL - (isConstantRight && colDataIsNull_s(pInputData[1], 0))) { // right operand is constant NULL + if (hasNullType || // one of operant is NULL type + (isConstantLeft && colDataIsNull_s(pInputData[0], 0)) || // left operand is constant NULL + (isConstantRight && colDataIsNull_s(pInputData[1], 0))) { // right operand is constant NULL colDataSetNNULL(pOutputData, 0, numOfRows); code = TSDB_CODE_SUCCESS; - } - else { + } else { int32_t iLeft = 0; int32_t iRight = 0; for (int32_t i = 0; i < numOfRows; ++i) { @@ -309,103 +265,78 @@ int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput, continue; } - code = executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TAOS_CHECK_RETURN(executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData)); } } - return code; + TAOS_RETURN(code); } -int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput, - bool swapAllowed, _geomDoRelationFunc_t doRelationFn) { +int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput, bool swapAllowed, + _geomDoRelationFunc_t doRelationFn) { int32_t code = TSDB_CODE_FAILED; - code = initCtxRelationFunc(); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TAOS_CHECK_RETURN(initCtxRelationFunc()); // handle with all NULL output - bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); - bool isConstant1 = (pInput[0].numOfRows == 1); - bool isConstant2 = (pInput[1].numOfRows == 1); + bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); + bool isConstant1 = (pInput[0].numOfRows == 1); + bool isConstant2 = (pInput[1].numOfRows == 1); int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); pOutput->numOfRows = numOfRows; SColumnInfoData *pOutputData = pOutput->columnData; - if (hasNullType || // at least one of operant is NULL type - (isConstant1 && colDataIsNull_s(pInput[0].columnData, 0)) || // left operand is constant NULL - (isConstant2 && colDataIsNull_s(pInput[1].columnData, 0))) { // right operand is constant NULL + if (hasNullType || // at least one of operant is NULL type + (isConstant1 && colDataIsNull_s(pInput[0].columnData, 0)) || // left operand is constant NULL + (isConstant2 && colDataIsNull_s(pInput[1].columnData, 0))) { // right operand is constant NULL colDataSetNNULL(pOutputData, 0, numOfRows); - code = TSDB_CODE_SUCCESS; - return code; + TAOS_RETURN(TSDB_CODE_SUCCESS); } - bool swapped = false; + bool swapped = false; SColumnInfoData *pInputData[2]; // swap two input data to make sure input data 0 is constant if swapAllowed and only isConstant2 is true - if (swapAllowed && - !isConstant1 && isConstant2) { + if (swapAllowed && !isConstant1 && isConstant2) { pInputData[0] = pInput[1].columnData; pInputData[1] = pInput[0].columnData; isConstant1 = true; isConstant2 = false; swapped = true; - } - else { + } else { pInputData[0] = pInput[0].columnData; pInputData[1] = pInput[1].columnData; } - GEOSGeometry *geom1 = NULL; - GEOSGeometry *geom2 = NULL; + GEOSGeometry *geom1 = NULL; + GEOSGeometry *geom2 = NULL; const GEOSPreparedGeometry *preparedGeom1 = NULL; // if there is constant, make PreparedGeometry from pInputData 0 if (isConstant1) { - code = readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1), NULL, _exit); } if (isConstant2) { - code = readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL), NULL, _exit); } for (int32_t i = 0; i < numOfRows; ++i) { - if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) || - (!isConstant2 && colDataIsNull_s(pInputData[1], i))) { + if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) || (!isConstant2 && colDataIsNull_s(pInputData[1], i))) { colDataSetNULL(pOutputData, i); code = TSDB_CODE_SUCCESS; continue; } if (!isConstant1) { - code = readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1), NULL, _exit); } if (!isConstant2) { - code = readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL), NULL, _exit); } - code = executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TAOS_CHECK_GOTO(executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn), NULL, + _exit); if (!isConstant1) { destroyGeometry(&geom1, &preparedGeom1); @@ -419,7 +350,7 @@ _exit: destroyGeometry(&geom1, &preparedGeom1); destroyGeometry(&geom2, NULL); - return code; + TAOS_RETURN(code); } int32_t makePointFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { diff --git a/source/libs/geometry/src/geosWrapper.c b/source/libs/geometry/src/geosWrapper.c index c5250c8481..2142b3d62d 100644 --- a/source/libs/geometry/src/geosWrapper.c +++ b/source/libs/geometry/src/geosWrapper.c @@ -18,7 +18,8 @@ #include "types.h" typedef char (*_geosRelationFunc_t)(GEOSContextHandle_t handle, const GEOSGeometry *g1, const GEOSGeometry *g2); -typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1, const GEOSGeometry *g2); +typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1, + const GEOSGeometry *g2); void geosFreeBuffer(void *buffer) { if (buffer) { @@ -27,13 +28,13 @@ void geosFreeBuffer(void *buffer) { } void geosErrMsgeHandler(const char *errMsg, void *userData) { - char* targetErrMsg = userData; + char *targetErrMsg = userData; snprintf(targetErrMsg, 512, "%s", errMsg); } int32_t initCtxMakePoint() { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (geosCtx->handle == NULL) { geosCtx->handle = GEOS_init_r(); @@ -41,7 +42,7 @@ int32_t initCtxMakePoint() { return code; } - GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); + (void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); } if (geosCtx->WKBWriter == NULL) { @@ -57,10 +58,10 @@ int32_t initCtxMakePoint() { // outputWKT is a zero ending string // need to call geosFreeBuffer(*outputGeom) later int32_t doMakePoint(double x, double y, unsigned char **outputGeom, size_t *size) { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); - GEOSGeometry *geom = NULL; + GEOSGeometry *geom = NULL; unsigned char *wkb = NULL; geom = GEOSGeom_createPointFromXY_r(geosCtx->handle, x, y); @@ -89,6 +90,10 @@ _exit: static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) { int32_t code = 0; char *wktPatternWithSpace = taosMemoryCalloc(4, 1024); + if (NULL == wktPatternWithSpace) { + return TSDB_CODE_OUT_OF_MEMORY; + } + sprintf( wktPatternWithSpace, "^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( " @@ -148,8 +153,8 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData } int32_t initCtxGeomFromText() { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (geosCtx->handle == NULL) { geosCtx->handle = GEOS_init_r(); @@ -157,7 +162,7 @@ int32_t initCtxGeomFromText() { return code; } - GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); + (void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); } if (geosCtx->WKTReader == NULL) { @@ -184,15 +189,15 @@ int32_t initCtxGeomFromText() { // inputWKT is a zero ending string // need to call geosFreeBuffer(*outputGeom) later int32_t doGeomFromText(const char *inputWKT, unsigned char **outputGeom, size_t *size) { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); - GEOSGeometry *geom = NULL; + GEOSGeometry *geom = NULL; unsigned char *wkb = NULL; if (doRegExec(inputWKT, geosCtx->WKTRegex, geosCtx->WKTMatchData) != 0) { - code = TSDB_CODE_FUNC_FUNTION_PARA_VALUE; - goto _exit; + code = TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + goto _exit; } geom = GEOSWKTReader_read_r(geosCtx->handle, geosCtx->WKTReader, inputWKT); @@ -219,8 +224,8 @@ _exit: } int32_t initCtxAsText() { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (geosCtx->handle == NULL) { geosCtx->handle = GEOS_init_r(); @@ -228,7 +233,7 @@ int32_t initCtxAsText() { return code; } - GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); + (void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); } if (geosCtx->WKBReader == NULL) { @@ -255,10 +260,10 @@ int32_t initCtxAsText() { // outputWKT is a zero ending string // need to call geosFreeBuffer(*outputWKT) later int32_t doAsText(const unsigned char *inputGeom, size_t size, char **outputWKT) { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); - GEOSGeometry *geom = NULL; + GEOSGeometry *geom = NULL; unsigned char *wkt = NULL; geom = GEOSWKBReader_read_r(geosCtx->handle, geosCtx->WKBReader, inputGeom, size); @@ -286,8 +291,8 @@ _exit: } int32_t initCtxRelationFunc() { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + int32_t code = TSDB_CODE_FAILED; + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (geosCtx->handle == NULL) { geosCtx->handle = GEOS_init_r(); @@ -295,7 +300,7 @@ int32_t initCtxRelationFunc() { return code; } - GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); + (void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg); } if (geosCtx->WKBReader == NULL) { @@ -309,88 +314,81 @@ int32_t initCtxRelationFunc() { } int32_t doGeosRelation(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, - bool swapped, char *res, - _geosRelationFunc_t relationFn, - _geosRelationFunc_t swappedRelationFn, + bool swapped, char *res, _geosRelationFunc_t relationFn, _geosRelationFunc_t swappedRelationFn, _geosPreparedRelationFunc_t preparedRelationFn, _geosPreparedRelationFunc_t swappedPreparedRelationFn) { - int32_t code = TSDB_CODE_FAILED; - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (!preparedGeom1) { if (!swapped) { ASSERT(relationFn); *res = relationFn(geosCtx->handle, geom1, geom2); - } - else { + } else { ASSERT(swappedRelationFn); *res = swappedRelationFn(geosCtx->handle, geom1, geom2); } - } - else { + } else { if (!swapped) { ASSERT(preparedRelationFn); *res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2); - } - else { + } else { ASSERT(swappedPreparedRelationFn); *res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2); } } - code = TSDB_CODE_SUCCESS; - return code; + return TSDB_CODE_SUCCESS; } int32_t doIntersects(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, bool swapped, char *res) { - return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, - GEOSIntersects_r, GEOSIntersects_r, GEOSPreparedIntersects_r, GEOSPreparedIntersects_r); + return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSIntersects_r, GEOSIntersects_r, + GEOSPreparedIntersects_r, GEOSPreparedIntersects_r); } int32_t doEquals(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, bool swapped, char *res) { - return doGeosRelation(geom1, NULL, geom2, swapped, res, - GEOSEquals_r, GEOSEquals_r, NULL, NULL); // no prepared version for eguals() + return doGeosRelation(geom1, NULL, geom2, swapped, res, GEOSEquals_r, GEOSEquals_r, NULL, + NULL); // no prepared version for eguals() } int32_t doTouches(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, bool swapped, char *res) { - return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, - GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r, GEOSPreparedTouches_r); + return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r, + GEOSPreparedTouches_r); } int32_t doCovers(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, bool swapped, char *res) { - return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, - GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r, GEOSPreparedCoveredBy_r); + return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r, + GEOSPreparedCoveredBy_r); } int32_t doContains(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, bool swapped, char *res) { - return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, - GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r, GEOSPreparedWithin_r); + return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r, + GEOSPreparedWithin_r); } -int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2, - bool swapped, char *res) { - return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, - NULL, NULL, GEOSPreparedContainsProperly_r, NULL); +int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, + const GEOSGeometry *geom2, bool swapped, char *res) { + return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, NULL, NULL, GEOSPreparedContainsProperly_r, NULL); } // input is with VARSTR format // need to call destroyGeometry(outputGeom, outputPreparedGeom) later -int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, const GEOSPreparedGeometry **outputPreparedGeom) { - SGeosContext* geosCtx = getThreadLocalGeosCtx(); +int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, + const GEOSPreparedGeometry **outputPreparedGeom) { + SGeosContext *geosCtx = getThreadLocalGeosCtx(); - ASSERT(outputGeom); //it is not allowed if outputGeom is NULL + ASSERT(outputGeom); // it is not allowed if outputGeom is NULL *outputGeom = NULL; - if (outputPreparedGeom) { //it means not to generate PreparedGeometry if outputPreparedGeom is NULL + if (outputPreparedGeom) { // it means not to generate PreparedGeometry if outputPreparedGeom is NULL *outputPreparedGeom = NULL; } - if (varDataLen(input) == 0) { //empty value + if (varDataLen(input) == 0) { // empty value return TSDB_CODE_SUCCESS; } @@ -410,7 +408,7 @@ int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, cons } void destroyGeometry(GEOSGeometry **geom, const GEOSPreparedGeometry **preparedGeom) { - SGeosContext* geosCtx = getThreadLocalGeosCtx(); + SGeosContext *geosCtx = getThreadLocalGeosCtx(); if (preparedGeom && *preparedGeom) { GEOSPreparedGeom_destroy_r(geosCtx->handle, *preparedGeom);