From b1ac114510bc6d1c19da8c15429914002b479113 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 29 Sep 2020 10:26:50 +0800 Subject: [PATCH] TD-1530 --- src/inc/taosdef.h | 4 ++-- src/plugins/http/src/httpGcJson.c | 6 +++--- src/plugins/http/src/httpRestJson.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 75d1e39a92..115630d1a5 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -145,8 +145,8 @@ do { \ #define GET_FLOAT_VAL(x) taos_align_get_float(x) #define GET_DOUBLE_VAL(x) taos_align_get_double(x) - #define SET_FLOAT_VAL(x, y) { float z = (float)(y); (*(int32_t*) x = *(int32_t*)z); } - #define SET_DOUBLE_VAL(x, y) { double z = (double)(y); (*(int64_t*) x = *(int64_t*)z); } + #define SET_FLOAT_VAL(x, y) { float z = (float)(y); (*(int32_t*) x = *(int32_t*)(&z)); } + #define SET_DOUBLE_VAL(x, y) { double z = (double)(y); (*(int64_t*) x = *(int64_t*)(&z)); } #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); } #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); } #else diff --git a/src/plugins/http/src/httpGcJson.c b/src/plugins/http/src/httpGcJson.c index fde8ae2176..d50a38201f 100644 --- a/src/plugins/http/src/httpGcJson.c +++ b/src/plugins/http/src/httpGcJson.c @@ -148,10 +148,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%" PRId64, fields[i].name, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, *((float *)row[i])); + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, GET_FLOAT_VAL(row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, *((double *)row[i])); + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: @@ -213,7 +213,7 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, httpJsonFloat(jsonBuf, *((float *)row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - httpJsonDouble(jsonBuf, *((double *)row[i])); + httpJsonDouble(jsonBuf, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: diff --git a/src/plugins/http/src/httpRestJson.c b/src/plugins/http/src/httpRestJson.c index f8912331a3..954678c24c 100644 --- a/src/plugins/http/src/httpRestJson.c +++ b/src/plugins/http/src/httpRestJson.c @@ -124,10 +124,10 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, httpJsonInt64(jsonBuf, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT: - httpJsonFloat(jsonBuf, *((float *)row[i])); + httpJsonFloat(jsonBuf, GET_FLOAT_VAL(row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - httpJsonDouble(jsonBuf, *((double *)row[i])); + httpJsonDouble(jsonBuf, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: -- GitLab