From a6c918bf4208302ae7efd5515c1dbd75ce4e5855 Mon Sep 17 00:00:00 2001 From: freemine Date: Sat, 17 Oct 2020 06:50:28 +0800 Subject: [PATCH] 1. msvc: C4244, conversion-loss-of-data 2. msvc: C4477, "%ld" => "%" PRId64 "" --- src/client/src/tscPrepare.c | 41 +++++++++++++++++----------------- src/connector/odbc/src/todbc.c | 22 +++++++++--------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index d6dd19db77..fe609da9a5 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -290,15 +290,15 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { if (u.v1==0 || u.v1==1) break; } break; case TSDB_DATA_TYPE_SMALLINT: { - u.v1 = *(int16_t*)bind->buffer; + u.v1 = (int8_t)*(int16_t*)bind->buffer; if (u.v1==0 || u.v1==1) break; } break; case TSDB_DATA_TYPE_INT: { - u.v1 = *(int32_t*)bind->buffer; + u.v1 = (int8_t)*(int32_t*)bind->buffer; if (u.v1==0 || u.v1==1) break; } break; case TSDB_DATA_TYPE_BIGINT: { - u.v1 = *(int64_t*)bind->buffer; + u.v1 = (int8_t)*(int64_t*)bind->buffer; if (u.v1==0 || u.v1==1) break; } break; case TSDB_DATA_TYPE_BINARY: @@ -334,19 +334,19 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { } break; case TSDB_DATA_TYPE_SMALLINT: { int16_t v = *(int16_t*)bind->buffer; - u.v1 = v; + u.v1 = (int8_t)v; if (v >= SCHAR_MIN && v <= SCHAR_MAX) break; return TSDB_CODE_TSC_INVALID_VALUE; } break; case TSDB_DATA_TYPE_INT: { int32_t v = *(int32_t*)bind->buffer; - u.v1 = v; + u.v1 = (int8_t)v; if (v >= SCHAR_MIN && v <= SCHAR_MAX) break; return TSDB_CODE_TSC_INVALID_VALUE; } break; case TSDB_DATA_TYPE_BIGINT: { int64_t v = *(int64_t*)bind->buffer; - u.v1 = v; + u.v1 = (int8_t)v; if (v >= SCHAR_MIN && v <= SCHAR_MAX) break; return TSDB_CODE_TSC_INVALID_VALUE; } break; @@ -354,9 +354,9 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { int64_t v; int n,r; - r = sscanf((const char*)bind->buffer, "%ld%n", &v, &n); + r = sscanf((const char*)bind->buffer, "%" PRId64 "%n", &v, &n); if (r==1 && n==strlen((const char*)bind->buffer)) { - u.v1 = v; + u.v1 = (int8_t)v; if (v >= SCHAR_MIN && v <= SCHAR_MAX) break; } return TSDB_CODE_TSC_INVALID_VALUE; @@ -377,17 +377,17 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: { int v = *(int16_t*)bind->buffer; - u.v2 = v; + u.v2 = (int16_t)v; } break; case TSDB_DATA_TYPE_INT: { int32_t v = *(int32_t*)bind->buffer; - u.v2 = v; + u.v2 = (int16_t)v; if (v >= SHRT_MIN && v <= SHRT_MAX) break; return TSDB_CODE_TSC_INVALID_VALUE; } break; case TSDB_DATA_TYPE_BIGINT: { int64_t v = *(int64_t*)bind->buffer; - u.v2 = v; + u.v2 = (int16_t)v; if (v >= SHRT_MIN && v <= SHRT_MAX) break; return TSDB_CODE_TSC_INVALID_VALUE; } break; @@ -395,9 +395,9 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { int64_t v; int n,r; - r = sscanf((const char*)bind->buffer, "%ld%n", &v, &n); + r = sscanf((const char*)bind->buffer, "%" PRId64 "%n", &v, &n); if (r==1 && n==strlen((const char*)bind->buffer)) { - u.v2 = v; + u.v2 = (int16_t)v; if (v >= SHRT_MIN && v <= SHRT_MAX) break; } return TSDB_CODE_TSC_INVALID_VALUE; @@ -430,7 +430,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { int64_t v; int n,r; - r = sscanf((const char*)bind->buffer, "%ld%n", &v, &n); + r = sscanf((const char*)bind->buffer, "%" PRId64 "%n", &v, &n); if (r==1 && n==strlen((const char*)bind->buffer)) { u.v4 = v; if (v >= INT_MIN && v <= INT_MAX) break; @@ -457,11 +457,11 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { u.f4 = *(int16_t*)bind->buffer; } break; case TSDB_DATA_TYPE_INT: { - u.f4 = *(int32_t*)bind->buffer; + u.f4 = (float)*(int32_t*)bind->buffer; // shall we check equality? } break; case TSDB_DATA_TYPE_BIGINT: { - u.f4 = *(int64_t*)bind->buffer; + u.f4 = (float)*(int64_t*)bind->buffer; // shall we check equality? } break; case TSDB_DATA_TYPE_FLOAT: { @@ -509,7 +509,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { int64_t v; int n,r; - r = sscanf((const char*)bind->buffer, "%ld%n", &v, &n); + r = sscanf((const char*)bind->buffer, "%" PRId64 "%n", &v, &n); if (r==1 && n==strlen((const char*)bind->buffer)) { u.v8 = v; break; @@ -539,7 +539,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { u.f8 = *(int32_t*)bind->buffer; } break; case TSDB_DATA_TYPE_BIGINT: { - u.f8 = *(int64_t*)bind->buffer; + u.f8 = (double)*(int64_t*)bind->buffer; } break; case TSDB_DATA_TYPE_FLOAT: { u.f8 = *(float*)bind->buffer; @@ -553,7 +553,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { int n,r; r = sscanf((const char*)bind->buffer, "%lf%n", &v, &n); if (r==1 && n==strlen((const char*)bind->buffer)) { - u.v8 = v; + u.f8 = v; break; } return TSDB_CODE_TSC_INVALID_VALUE; @@ -574,7 +574,8 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: { // is this the correct way to call taosParseTime? - if (taosParseTime(bind->buffer, &u.v8, *bind->length, 3, tsDaylight) == TSDB_CODE_SUCCESS) { + int32_t len = (int32_t)*bind->length; + if (taosParseTime(bind->buffer, &u.v8, len, 3, tsDaylight) == TSDB_CODE_SUCCESS) { break; } return TSDB_CODE_TSC_INVALID_VALUE; diff --git a/src/connector/odbc/src/todbc.c b/src/connector/odbc/src/todbc.c index 45f005a7ed..518c98b41f 100644 --- a/src/connector/odbc/src/todbc.c +++ b/src/connector/odbc/src/todbc.c @@ -2690,7 +2690,7 @@ static SQLRETURN conv_tsdb_v8_to_c_double(sql_t *sql, c_target_t *target, TAOS_F static SQLRETURN conv_tsdb_v8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) { char buf[64]; - int n = snprintf(buf, sizeof(buf), "%ld", v8); + int n = snprintf(buf, sizeof(buf), "%" PRId64 "", v8); DASSERT(nsoi = n; strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); @@ -2702,7 +2702,7 @@ static SQLRETURN conv_tsdb_v8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIE static SQLRETURN conv_tsdb_v8_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) { char buf[64]; - int n = snprintf(buf, sizeof(buf), "%ld", v8); + int n = snprintf(buf, sizeof(buf), "%" PRId64 "", v8); DASSERT(nsoi = n; strncpy(target->ptr, buf, (n>target->len ? target->len : n)); @@ -3053,7 +3053,7 @@ static SQLRETURN conv_tsdb_str_to_c_v8(sql_t *sql, c_target_t *target, TAOS_FIEL } char buf[64]; - snprintf(buf, sizeof(buf), "%ld", v); + snprintf(buf, sizeof(buf), "%" PRId64 "", v); if (strcmp(buf, str)==0) return SQL_SUCCESS; @@ -3156,7 +3156,7 @@ const char* tsdb_int64_to_ts(int64_t src, int64_t *dst) *dst = src; char buf[4096]; - int n = snprintf(buf, sizeof(buf), "%ld", src); + int n = snprintf(buf, sizeof(buf), "%" PRId64 "", src); DASSERT(n>=0); DASSERT(n