diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 69bc4a3e20049aaa520df99393dcb17a80950ab4..4020d201ce4fcb84cf9e27857bfc07e204b4f203 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -46,18 +46,20 @@ static int32_t tscToInteger(SSQLToken *pToken, int64_t *value, char **endPtr) { return TK_ILLEGAL; } - int32_t radix = 10; - - int32_t radixList[3] = {16, 8, 2}; // the integer number with different radix: hex, oct, bin - if (pToken->type == TK_HEX || pToken->type == TK_OCT || pToken->type == TK_BIN) { - radix = radixList[pToken->type - TK_HEX]; - } - errno = 0; - *value = strtoll(pToken->z, endPtr, radix); + *value = strtoll(pToken->z, endPtr, 0); + if (**endPtr == 'e' || **endPtr == 'E' || **endPtr == '.') { + errno = 0; + double v = round(strtod(pToken->z, endPtr)); + if (v > INT64_MAX || v <= INT64_MIN) { + errno = ERANGE; + } else { + *value = v; + } + } // not a valid integer number, return error - if ((pToken->type == TK_STRING || pToken->type == TK_ID) && ((*endPtr - pToken->z) != pToken->n)) { + if (*endPtr - pToken->z != pToken->n) { return TK_ILLEGAL; } @@ -73,11 +75,11 @@ static int32_t tscToDouble(SSQLToken *pToken, double *value, char **endPtr) { *value = strtod(pToken->z, endPtr); // not a valid integer number, return error - if ((pToken->type == TK_STRING || pToken->type == TK_ID) && ((*endPtr - pToken->z) != pToken->n)) { + if ((*endPtr - pToken->z) != pToken->n) { return TK_ILLEGAL; - } else { - return pToken->type; } + + return pToken->type; } int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int16_t timePrec) {