diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index ad6cfc8b95..90b8e9dd8a 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 d5762ef87d..da1fbd364f 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -258,79 +258,99 @@ char *taosStrCaseStr(const char *str, const char *pattern) { 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