diff --git a/cmake/cmake.install b/cmake/cmake.install index f51c6566fa1058daf3454ef09452981f09584ce4..b2421fac2598d03f271ec2c35896433b796f08a2 100644 --- a/cmake/cmake.install +++ b/cmake/cmake.install @@ -5,22 +5,27 @@ IF (TD_LINUX) ELSEIF (TD_WINDOWS) SET(CMAKE_INSTALL_PREFIX C:/TDengine) - INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/go DESTINATION connector) - INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/nodejs DESTINATION connector) - INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/python DESTINATION connector) - INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/C\# DESTINATION connector) - INSTALL(DIRECTORY ${TD_SOURCE_DIR}/examples DESTINATION .) + # INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/go DESTINATION connector) + # INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/nodejs DESTINATION connector) + # INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/python DESTINATION connector) + # INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/C\# DESTINATION connector) + # INSTALL(DIRECTORY ${TD_SOURCE_DIR}/examples DESTINATION .) INSTALL(FILES ${TD_SOURCE_DIR}/packaging/cfg/taos.cfg DESTINATION cfg) - INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taos.h DESTINATION include) - INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taoserror.h DESTINATION include) + INSTALL(FILES ${TD_SOURCE_DIR}/include/client/taos.h DESTINATION include) + INSTALL(FILES ${TD_SOURCE_DIR}/include/util/taoserror.h DESTINATION include) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos_static.lib DESTINATION driver) - INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver) + INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .) + INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taosd.exe DESTINATION .) + INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/udfd.exe DESTINATION .) IF (TD_MVN_INSTALLED) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.38-dist.jar DESTINATION connector/jdbc) ENDIF () + SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.bat") + INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")") + INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} :needAdmin ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Windows ${TD_VER_NUMBER})") ELSEIF (TD_DARWIN) SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh") INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")") diff --git a/include/os/osString.h b/include/os/osString.h index 5f65f97bec05b37ae9e901cab51f342c96f5bbd0..1b518f9b81ee6879b4dde6524ca9bd920d31b0e2 100644 --- a/include/os/osString.h +++ b/include/os/osString.h @@ -38,6 +38,13 @@ typedef int32_t TdUcs4; #define wcsncpy WCSNCPY_FUNC_TAOS_FORBID #define wchar_t WCHAR_T_TYPE_TAOS_FORBID #define strcasestr STR_CASE_STR_FORBID + #define strtoll STR_TO_LL_FUNC_TAOS_FORBID + #define strtoull STR_TO_ULL_FUNC_TAOS_FORBID + #define strtol STR_TO_L_FUNC_TAOS_FORBID + #define strtoul STR_TO_UL_FUNC_TAOS_FORBID + #define strtod STR_TO_LD_FUNC_TAOS_FORBID + #define strtold STR_TO_D_FUNC_TAOS_FORBID + #define strtof STR_TO_F_FUNC_TAOS_FORBID #endif #ifdef WINDOWS @@ -72,6 +79,17 @@ int32_t taosWcharsToMbs(char *pStrs, TdWchar *pWchars, int32_t size); char *taosStrCaseStr(const char *str, const char *pattern); +int64_t taosStr2Int64(const char *str, char** pEnd, int32_t radix); +uint64_t taosStr2UInt64(const char *str, char** pEnd, int32_t radix); +int32_t taosStr2Int32(const char *str, char** pEnd, int32_t radix); +uint32_t taosStr2UInt32(const char *str, char** pEnd, int32_t radix); +int16_t taosStr2Int16(const char *str, char** pEnd, int32_t radix); +uint16_t taosStr2UInt16(const char *str, char** pEnd, int32_t radix); +int8_t taosStr2Int8(const char *str, char** pEnd, int32_t radix); +uint8_t taosStr2UInt8(const char *str, char** pEnd, int32_t radix); +double taosStr2Double(const char *str, char** pEnd); +float taosStr2Float(const char *str, char** pEnd); + #ifdef __cplusplus } #endif diff --git a/packaging/tools/make_install.bat b/packaging/tools/make_install.bat new file mode 100644 index 0000000000000000000000000000000000000000..64f30b8465bc48951603fd674eccafc2a5e73432 --- /dev/null +++ b/packaging/tools/make_install.bat @@ -0,0 +1,6 @@ +@echo off +goto %1 +:needAdmin +mshta vbscript:createobject("shell.application").shellexecute("%~s0",":hasAdmin","","runas",1)(window.close)&goto :eof +:hasAdmin +cp -f C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 \ No newline at end of file diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index f6f8db859075dd8accff0e21efed38fc7ec0bb46..d5377c99a653b35c0b19faba92e98ec812b6d65b 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -580,7 +580,7 @@ static bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg){ const char *pVal = kvVal->value; int32_t len = kvVal->length; char *endptr = NULL; - double result = strtod(pVal, &endptr); + double result = taosStr2Double(pVal, &endptr); if(pVal == endptr){ smlBuildInvalidDataMsg(msg, "invalid data", pVal); return false; @@ -714,7 +714,7 @@ static bool smlIsNchar(const char *pVal, uint16_t len) { static int64_t smlGetTimeValue(const char *value, int32_t len, int8_t type) { char *endPtr = NULL; - int64_t tsInt64 = strtoll(value, &endPtr, 10); + int64_t tsInt64 = taosStr2Int64(value, &endPtr, 10); if(value + len != endPtr){ return -1; } diff --git a/source/common/src/tname.c b/source/common/src/tname.c index fa9b6e1e63628593aca1fb27ead10ec6a7bff7d1..0764ea84b9f54b0485e90a2c0bef5b3b5e771a1e 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -250,7 +250,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { return -1; } - dst->acctId = strtoll(str, NULL, 10); + dst->acctId = taosStr2Int32(str, NULL, 10); } if ((type & T_NAME_DB) == T_NAME_DB) { diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 62a71796262314d40a3f984b3933376370110605..69ba964187fe44f33b4df1ab8b5c7706a8569eec 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -590,7 +590,7 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura char* endPtr = NULL; /* get the basic numeric value */ - int64_t timestamp = strtoll(token, &endPtr, 10); + int64_t timestamp = taosStr2Int64(token, &endPtr, 10); if (errno != 0) { return -1; } @@ -608,7 +608,7 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati errno = 0; /* get the basic numeric value */ - *duration = strtoll(token, NULL, 10); + *duration = taosStr2Int64(token, NULL, 10); if (errno != 0) { return -1; } diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index e44450fe6e933a850e3beb25939adf08e2da055a..7b0bef4918394b777ff8836245e1d22c14d156a8 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -39,7 +39,7 @@ int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value) { errno = 0; char *endPtr = NULL; - *value = strtoll(z, &endPtr, base); + *value = taosStr2Int64(z, &endPtr, base); if (errno == ERANGE || errno == EINVAL || endPtr - z != n) { errno = 0; return -1; @@ -58,7 +58,7 @@ int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value) { return -1; } - *value = strtoull(z, &endPtr, base); + *value = taosStr2UInt64(z, &endPtr, base); if (errno == ERANGE || errno == EINVAL || endPtr - z != n) { errno = 0; return -1; @@ -434,7 +434,7 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val // return -1; // } // - // *value = strtod(pStr, NULL); + // *value = taosStr2Double(pStr, NULL); return 0; } @@ -911,7 +911,7 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) { case TSDB_DATA_TYPE_DOUBLE: { if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { errno = 0; - double v = strtod(pVariant->pz, NULL); + double v = taosStr2Double(pVariant->pz, NULL); if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { taosMemoryFree(pVariant->pz); return -1; diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 802cdf7aad1a3ae2f054225a7d8ac9bef1e60314..4c23e4ba4b9a89d124a93a434da27158891816bc 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -118,21 +118,21 @@ TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t d } return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_FLOAT) { - float va = strtod(a, NULL); + float va = taosStr2Float(a, NULL); if (errno == ERANGE && va == -1) { return CONTINUE; } - float vb = strtod(b, NULL); + float vb = taosStr2Float(b, NULL); if (errno == ERANGE && va == -1) { return CONTINUE; } return tDoCompare(func, cmptype, &va, &vb); } else if (dtype == TSDB_DATA_TYPE_DOUBLE) { - double va = strtod(a, NULL); + double va = taosStr2Double(a, NULL); if (errno == ERANGE && va == -1) { return CONTINUE; } - double vb = strtod(b, NULL); + double vb = taosStr2Double(b, NULL); if (errno == ERANGE && va == -1) { return CONTINUE; } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index a438a1e843c71aaa7d7a7b68fbdb75b49b2af162..894659ddd15f52144727117aa076fede9087eadc 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -123,7 +123,7 @@ static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, ch pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT); } else { strncpy(pFqdn, ep, pColon - ep); - *pPort = strtol(pColon + 1, NULL, 10); + *pPort = taosStr2Int32(pColon + 1, NULL, 10); if (*pPort >= UINT16_MAX || *pPort <= 0) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); } @@ -147,7 +147,7 @@ static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t if (NULL == pPortToken) { pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else { - *pPort = strtol(pPortToken->z, NULL, 10); + *pPort = taosStr2Int32(pPortToken->z, NULL, 10); if (*pPort >= UINT16_MAX || *pPort <= 0) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); } @@ -476,9 +476,9 @@ SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) { SLimitNode* limitNode = (SLimitNode*)nodesMakeNode(QUERY_NODE_LIMIT); CHECK_OUT_OF_MEM(limitNode); - limitNode->limit = strtol(pLimit->z, NULL, 10); + limitNode->limit = taosStr2Int64(pLimit->z, NULL, 10); if (NULL != pOffset) { - limitNode->offset = strtol(pOffset->z, NULL, 10); + limitNode->offset = taosStr2Int64(pOffset->z, NULL, 10); } return (SNode*)limitNode; } @@ -694,59 +694,59 @@ SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) { SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) { switch (type) { case DB_OPTION_BUFFER: - ((SDatabaseOptions*)pOptions)->buffer = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->buffer = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_CACHELAST: - ((SDatabaseOptions*)pOptions)->cachelast = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->cachelast = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_COMP: - ((SDatabaseOptions*)pOptions)->compressionLevel = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->compressionLevel = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_DAYS: { SToken* pToken = pVal; if (TK_NK_INTEGER == pToken->type) { - ((SDatabaseOptions*)pOptions)->daysPerFile = strtol(pToken->z, NULL, 10) * 1440; + ((SDatabaseOptions*)pOptions)->daysPerFile = taosStr2Int32(pToken->z, NULL, 10) * 1440; } else { ((SDatabaseOptions*)pOptions)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, pToken); } break; } case DB_OPTION_FSYNC: - ((SDatabaseOptions*)pOptions)->fsyncPeriod = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->fsyncPeriod = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_MAXROWS: - ((SDatabaseOptions*)pOptions)->maxRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->maxRowsPerBlock = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_MINROWS: - ((SDatabaseOptions*)pOptions)->minRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->minRowsPerBlock = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_KEEP: ((SDatabaseOptions*)pOptions)->pKeep = pVal; break; case DB_OPTION_PAGES: - ((SDatabaseOptions*)pOptions)->pages = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->pages = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_PAGESIZE: - ((SDatabaseOptions*)pOptions)->pagesize = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->pagesize = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_PRECISION: copyStringFormStringToken((SToken*)pVal, ((SDatabaseOptions*)pOptions)->precisionStr, sizeof(((SDatabaseOptions*)pOptions)->precisionStr)); break; case DB_OPTION_REPLICA: - ((SDatabaseOptions*)pOptions)->replica = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->replica = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_STRICT: - ((SDatabaseOptions*)pOptions)->strict = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->strict = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_WAL: - ((SDatabaseOptions*)pOptions)->walLevel = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->walLevel = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_VGROUPS: - ((SDatabaseOptions*)pOptions)->numOfVgroups = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->numOfVgroups = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_SINGLE_STABLE: - ((SDatabaseOptions*)pOptions)->singleStable = strtol(((SToken*)pVal)->z, NULL, 10); + ((SDatabaseOptions*)pOptions)->singleStable = taosStr2Int8(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_RETENTIONS: ((SDatabaseOptions*)pOptions)->pRetentions = pVal; @@ -827,16 +827,16 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType sizeof(((STableOptions*)pOptions)->comment)); break; case TABLE_OPTION_DELAY: - ((STableOptions*)pOptions)->delay = strtol(((SToken*)pVal)->z, NULL, 10); + ((STableOptions*)pOptions)->delay = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case TABLE_OPTION_FILE_FACTOR: - ((STableOptions*)pOptions)->filesFactor = strtod(((SToken*)pVal)->z, NULL); + ((STableOptions*)pOptions)->filesFactor = taosStr2Float(((SToken*)pVal)->z, NULL); break; case TABLE_OPTION_ROLLUP: ((STableOptions*)pOptions)->pRollupFuncs = pVal; break; case TABLE_OPTION_TTL: - ((STableOptions*)pOptions)->ttl = strtol(((SToken*)pVal)->z, NULL, 10); + ((STableOptions*)pOptions)->ttl = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); break; case TABLE_OPTION_SMA: ((STableOptions*)pOptions)->pSma = pVal; @@ -868,7 +868,7 @@ SDataType createDataType(uint8_t type) { } SDataType createVarLenDataType(uint8_t type, const SToken* pLen) { - SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = strtol(pLen->z, NULL, 10)}; + SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = taosStr2Int16(pLen->z, NULL, 10)}; return dt; } @@ -1119,7 +1119,7 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) { SDropDnodeStmt* pStmt = (SDropDnodeStmt*)nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT); CHECK_OUT_OF_MEM(pStmt); if (TK_NK_INTEGER == pDnode->type) { - pStmt->dnodeId = strtol(pDnode->z, NULL, 10); + pStmt->dnodeId = taosStr2Int32(pDnode->z, NULL, 10); } else { if (!checkAndSplitEndpoint(pCxt, pDnode, pStmt->fqdn, &pStmt->port)) { nodesDestroyNode(pStmt); @@ -1133,7 +1133,7 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const const SToken* pValue) { SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnode->z, NULL, 10); + pStmt->dnodeId = taosStr2Int32(pDnode->z, NULL, 10); trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config)); if (NULL != pValue) { trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value)); @@ -1183,7 +1183,7 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SCreateComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10); ; return (SNode*)pStmt; } @@ -1191,7 +1191,7 @@ SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, co SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SDropComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10); ; return (SNode*)pStmt; } @@ -1251,7 +1251,7 @@ SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* } SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) { - ((SExplainOptions*)pOptions)->ratio = strtod(pVal->z, NULL); + ((SExplainOptions*)pOptions)->ratio = taosStr2Double(pVal->z, NULL); return pOptions; } @@ -1347,7 +1347,7 @@ SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId) { SKillStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->targetId = strtol(pId->z, NULL, 10); + pStmt->targetId = taosStr2Int32(pId->z, NULL, 10); return (SNode*)pStmt; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 29951ccdee3a818ea41029cf43f27306d30af039..34ae13580b96720fe580de45dc4374eb71aa41d9 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -442,7 +442,7 @@ static bool isNullStr(SToken* pToken) { static FORCE_INLINE int32_t toDouble(SToken* pToken, double* value, char** endPtr) { errno = 0; - *value = strtold(pToken->z, endPtr); + *value = taosStr2Double(pToken->z, endPtr); // not a valid integer number, return error if ((*endPtr - pToken->z) != pToken->n) { @@ -482,9 +482,9 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } } else if (pToken->type == TK_NK_INTEGER) { - return func(pMsgBuf, ((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + return func(pMsgBuf, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); } else if (pToken->type == TK_NK_FLOAT) { - return func(pMsgBuf, ((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + return func(pMsgBuf, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); } else { return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 18e0843e9244b032cd0bd563c1dad6609aa21e32..0d214fd85e38cfe5500696115e9400f0298bde98 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -498,7 +498,7 @@ static int32_t parseTimeFromValueNode(SValueNode* pVal) { return TSDB_CODE_SUCCESS; } char* pEnd = NULL; - pVal->datum.i = strtoll(pVal->literal, &pEnd, 10); + pVal->datum.i = taosStr2Int64(pVal->literal, &pEnd, 10); return (NULL != pEnd && '\0' == *pEnd) ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED; } else { return TSDB_CODE_FAILED; @@ -527,61 +527,61 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD break; case TSDB_DATA_TYPE_TINYINT: { char* endPtr = NULL; - pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + pVal->datum.i = taosStr2Int64(pVal->literal, &endPtr, 10); *(int8_t*)&pVal->typeData = pVal->datum.i; break; } case TSDB_DATA_TYPE_SMALLINT: { char* endPtr = NULL; - pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + pVal->datum.i = taosStr2Int64(pVal->literal, &endPtr, 10); *(int16_t*)&pVal->typeData = pVal->datum.i; break; } case TSDB_DATA_TYPE_INT: { char* endPtr = NULL; - pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + pVal->datum.i = taosStr2Int64(pVal->literal, &endPtr, 10); *(int32_t*)&pVal->typeData = pVal->datum.i; break; } case TSDB_DATA_TYPE_BIGINT: { char* endPtr = NULL; - pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + pVal->datum.i = taosStr2Int64(pVal->literal, &endPtr, 10); *(int64_t*)&pVal->typeData = pVal->datum.i; break; } case TSDB_DATA_TYPE_UTINYINT: { char* endPtr = NULL; - pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + pVal->datum.u = taosStr2UInt64(pVal->literal, &endPtr, 10); *(uint8_t*)&pVal->typeData = pVal->datum.u; break; } case TSDB_DATA_TYPE_USMALLINT: { char* endPtr = NULL; - pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + pVal->datum.u = taosStr2UInt64(pVal->literal, &endPtr, 10); *(uint16_t*)&pVal->typeData = pVal->datum.u; break; } case TSDB_DATA_TYPE_UINT: { char* endPtr = NULL; - pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + pVal->datum.u = taosStr2UInt64(pVal->literal, &endPtr, 10); *(uint32_t*)&pVal->typeData = pVal->datum.u; break; } case TSDB_DATA_TYPE_UBIGINT: { char* endPtr = NULL; - pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + pVal->datum.u = taosStr2UInt64(pVal->literal, &endPtr, 10); *(uint64_t*)&pVal->typeData = pVal->datum.u; break; } case TSDB_DATA_TYPE_FLOAT: { char* endPtr = NULL; - pVal->datum.d = strtold(pVal->literal, &endPtr); + pVal->datum.d = taosStr2Double(pVal->literal, &endPtr); *(float*)&pVal->typeData = pVal->datum.d; break; } case TSDB_DATA_TYPE_DOUBLE: { char* endPtr = NULL; - pVal->datum.d = strtold(pVal->literal, &endPtr); + pVal->datum.d = taosStr2Double(pVal->literal, &endPtr); *(double*)&pVal->typeData = pVal->datum.d; break; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 795b5ca641920410b19a105f4a60c26fb15504e1..2d844e18429fbaaed9e6a61cf3234c7dc5da26a3 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -3863,7 +3863,7 @@ static YYACTIONTYPE yy_reduce( { yymsp[1].minor.yy140 = 0; } break; case 245: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy140 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy140 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; case 246: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ { pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy617, &yymsp[-4].minor.yy105, yymsp[-2].minor.yy172, yymsp[-3].minor.yy172, yymsp[0].minor.yy172); } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index d4a88622e2db99db1d3b7ba75d2b6705d6ca14e7..45742189d5e0585d68730a1c2f9843ecf58688b6 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -724,7 +724,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp case TSDB_DATA_TYPE_BIGINT: { if (inputType == TSDB_DATA_TYPE_BINARY) { memcpy(output, varDataVal(input), varDataLen(input)); - *(int64_t *)output = strtoll(output, NULL, 10); + *(int64_t *)output = taosStr2Int64(output, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); @@ -733,7 +733,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp return TSDB_CODE_FAILED; } newBuf[len] = 0; - *(int64_t *)output = strtoll(newBuf, NULL, 10); + *(int64_t *)output = taosStr2Int64(newBuf, NULL, 10); taosMemoryFree(newBuf); } else { GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input); @@ -743,7 +743,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp case TSDB_DATA_TYPE_UBIGINT: { if (inputType == TSDB_DATA_TYPE_BINARY) { memcpy(output, varDataVal(input), varDataLen(input)); - *(uint64_t *)output = strtoull(output, NULL, 10); + *(uint64_t *)output = taosStr2UInt64(output, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); @@ -752,7 +752,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp return TSDB_CODE_FAILED; } newBuf[len] = 0; - *(uint64_t *)output = strtoull(newBuf, NULL, 10); + *(uint64_t *)output = taosStr2UInt64(newBuf, NULL, 10); taosMemoryFree(newBuf); } else { GET_TYPED_DATA(*(uint64_t *)output, uint64_t, inputType, input); diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index c9fcaeb32e997a28767063a24b3868a95a324a63..19453bf7600128de3abd8a5f096ebf9c023b62ec 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -92,7 +92,7 @@ void convertStringToDouble(const void *inData, void *outData, int8_t inType, int tmp[len] = 0; ASSERT(outType == TSDB_DATA_TYPE_DOUBLE); - double value = strtod(tmp, NULL); + double value = taosStr2Double(tmp, NULL); *((double *)outData) = value; taosMemoryFreeClear(tmp); @@ -267,22 +267,22 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { switch (pOut->columnData->info.type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t value = (int8_t)strtoll(buf, NULL, 10); + int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10); colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t value = (int16_t)strtoll(buf, NULL, 10); + int16_t value = (int16_t)taosStr2Int16(buf, NULL, 10); colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); break; } case TSDB_DATA_TYPE_INT: { - int32_t value = (int32_t)strtoll(buf, NULL, 10); + int32_t value = (int32_t)taosStr2Int32(buf, NULL, 10); colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t value = (int64_t)strtoll(buf, NULL, 10); + int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10); colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); break; } @@ -292,22 +292,22 @@ static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowI static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { switch (pOut->columnData->info.type) { case TSDB_DATA_TYPE_UTINYINT: { - uint8_t value = (uint8_t)strtoull(buf, NULL, 10); + uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10); colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); break; } case TSDB_DATA_TYPE_USMALLINT: { - uint16_t value = (uint16_t)strtoull(buf, NULL, 10); + uint16_t value = (uint16_t)taosStr2UInt16(buf, NULL, 10); colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); break; } case TSDB_DATA_TYPE_UINT: { - uint32_t value = (uint32_t)strtoull(buf, NULL, 10); + uint32_t value = (uint32_t)taosStr2UInt32(buf, NULL, 10); colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); break; } case TSDB_DATA_TYPE_UBIGINT: { - uint64_t value = (uint64_t)strtoull(buf, NULL, 10); + uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10); colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); break; } @@ -315,12 +315,12 @@ static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t ro } static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) { - double value = strtod(buf, NULL); + double value = taosStr2Double(buf, NULL); colDataAppendDouble(pOut->columnData, rowIndex, &value); } static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) { - int64_t value = strtoll(buf, NULL, 10); + int64_t value = taosStr2Int64(buf, NULL, 10); bool v = (value != 0)? true:false; colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); } diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index ad6cfc8b95192a9818a87600cc6de72a9d635952..90b8e9dd8aca8d3ceaee32dc358225d60cf029b3 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -27,6 +27,9 @@ if(BUILD_ADDR2LINE) os PUBLIC addr2line dl z ) endif () +if(CHECK_STR2INT_ERROR) + add_definitions(-DTD_CHECK_STR_TO_INT_ERROR) +endif() target_link_libraries( os PUBLIC pthread ) diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 7dbd3019131073d60db594fdbbfda954fcc393d6..da1fbd364fe4085404bf653921b85ef7002837ea 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -254,4 +254,103 @@ char *taosStrCaseStr(const char *str, const char *pattern) { } } return NULL; +} + +int64_t taosStr2Int64(const char *str, char** pEnd, int32_t radix) { + int64_t tmp = strtoll(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); +#endif + return tmp; +} + +uint64_t taosStr2UInt64(const char *str, char** pEnd, int32_t radix) { + uint64_t tmp = strtoull(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); +#endif + return tmp; +} + +int32_t taosStr2Int32(const char *str, char** pEnd, int32_t radix) { + int32_t tmp = strtol(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); +#endif + return tmp; +} + +uint32_t taosStr2UInt32(const char *str, char** pEnd, int32_t radix) { + uint32_t tmp = strtol(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); +#endif + return tmp; +} + +int16_t taosStr2Int16(const char *str, char** pEnd, int32_t radix) { + int32_t tmp = strtol(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp >= SHRT_MIN); + assert(tmp <= SHRT_MAX); +#endif + return (int16_t)tmp; +} + +uint16_t taosStr2UInt16(const char *str, char** pEnd, int32_t radix) { + uint32_t tmp = strtoul(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp <= USHRT_MAX); +#endif + return (uint16_t)tmp; +} + +int8_t taosStr2Int8(const char *str, char** pEnd, int32_t radix) { + int32_t tmp = strtol(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp >= SCHAR_MIN); + assert(tmp <= SCHAR_MAX); +#endif + return tmp; +} + +uint8_t taosStr2UInt8(const char *str, char** pEnd, int32_t radix) { + uint32_t tmp = strtoul(str, pEnd, radix); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp <= UCHAR_MAX); +#endif + return tmp; +} + +double taosStr2Double(const char *str, char** pEnd) { + double tmp = strtod(str, pEnd); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp != HUGE_VAL); +#endif + return tmp; +} + +float taosStr2Float(const char *str, char** pEnd) { + float tmp = strtof(str, pEnd); +#ifdef TD_CHECK_STR_TO_INT_ERROR + assert(errno != ERANGE); + assert(errno != EINVAL); + assert(tmp != HUGE_VALF); + assert(tmp != NAN); +#endif + return tmp; } \ No newline at end of file diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index c5cd968fd9fdfc9c4bf9ff53b02046238aad1162..b15c188f04765bf7c7807a3bed43c58b47fac71a 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -187,7 +187,7 @@ int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal sscanf(p,"%lld",pVal); #else // sscanf(p,"%ld",pVal); - *pVal = strtol(p, NULL, 10); + *pVal = taosStr2Int64(p, NULL, 10); #endif return TSDB_CODE_SUCCESS; } @@ -222,7 +222,7 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV sscanf(p,"%llu",pVal); #else // sscanf(p,"%ld",pVal); - *pVal = strtoul(p, NULL, 10); + *pVal = taosStr2UInt64(p, NULL, 10); #endif return TSDB_CODE_SUCCESS; } diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 9f9c8821b04760e5c49d0edd87d58899e284a1fb..21474c316f48a5cb8b06b9a3e8a24916133ce06b 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -195,16 +195,16 @@ void shellRunSingleCommandImp(char *command) { et = taosGetTimestampUs(); if (error_no == 0) { - printf("Query OK, %d row(s) in set (%.6fs)\n", numOfRows, (et - st) / 1E6); + printf("Query OK, %d rows affected (%.6fs)\n", numOfRows, (et - st) / 1E6); } else { - printf("Query interrupted (%s), %d row(s) in set (%.6fs)\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); + printf("Query interrupted (%s), %d rows affected (%.6fs)\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); } taos_free_result(pSql); } else { int32_t num_rows_affacted = taos_affected_rows(pSql); taos_free_result(pSql); et = taosGetTimestampUs(); - printf("Query OK, %d of %d row(s) in database (%.6fs)\n", num_rows_affacted, num_rows_affacted, (et - st) / 1E6); + printf("Query OK, %d of %d rows affected (%.6fs)\n", num_rows_affacted, num_rows_affacted, (et - st) / 1E6); } printf("\n");