提交 776e0a39 编写于 作者: F freemine

add -Wconversion and refactor accordingly

上级 54ed76ec
......@@ -17,6 +17,8 @@ IF (TD_LINUX_64)
if(NOT FLEX_FOUND)
message(FATAL_ERROR "you need to install flex first")
else ()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests)
endif()
......
此差异已折叠。
......@@ -74,7 +74,7 @@ TSDB_CONV_CODE tsdb_iconv_conv(iconv_t cnv, const unsigned char *src, size_t *sl
size_t sl = *slen;
size_t dl = *dlen;
int n = iconv(cnv, &s, &sl, &d, &dl);
size_t n = iconv(cnv, &s, &sl, &d, &dl);
int e = errno;
if (dl) *d = '\0'; // what if all consumed?
......
......@@ -125,7 +125,7 @@ int string_conv(const char *fromcode, const char *tocode,
iconv_t conv = iconv_open(tocode, fromcode);
if (!conv) return -1;
int r = 0;
size_t r = 0;
do {
char *s = (char*)src;
char *d = (char*)dst;
......@@ -141,7 +141,7 @@ int string_conv(const char *fromcode, const char *tocode,
} while (0);
iconv_close(conv);
return r;
return (int)r;
}
int utf8_chars(const char *src)
......@@ -161,7 +161,7 @@ int utf8_chars(const char *src)
size_t chars = (sizeof(buf) - dlen) / 2;
iconv_close(conv);
return chars;
return (int)chars;
}
unsigned char* utf8_to_ucs4le(const char *utf8, size_t *chars)
......@@ -240,7 +240,7 @@ size_t wchars_to_chars2(const SQLWCHAR *src, size_t slen, SQLCHAR *dst, size_t d
{
size_t consumed=0, generated=0;
int n = string_conv("UCS-2LE", "UTF-8", (const unsigned char*)src, slen, dst, dlen, &consumed, &generated);
if (n) return -1;
if (n) return (size_t)-1;
return generated;
}
......@@ -248,7 +248,7 @@ size_t chars_to_wchars2(const SQLCHAR *src, size_t slen, SQLWCHAR *dst, size_t d
{
size_t consumed=0, generated=0;
int n = string_conv("UTF-8", "UCS-2LE", (const unsigned char*)src, slen, (unsigned char*)dst, dlen, &consumed, &generated);
if (n) return -1;
if (n) return (size_t)-1;
return generated;
}
......@@ -72,9 +72,9 @@ static int open_connect(const char *dsn, const char *uid, const char *pwd, SQLHE
CHK_RESULT(r, SQL_HANDLE_ENV, env, "");
if (r!=SQL_SUCCESS) break;
do {
r = SQLConnect(conn, (SQLCHAR*)dsn, strlen(dsn),
(SQLCHAR*)uid, strlen(uid),
(SQLCHAR*)pwd, strlen(pwd));
r = SQLConnect(conn, (SQLCHAR*)dsn, (SQLSMALLINT)strlen(dsn),
(SQLCHAR*)uid, (SQLSMALLINT)strlen(uid),
(SQLCHAR*)pwd, (SQLSMALLINT)strlen(pwd));
CHK_RESULT(r, SQL_HANDLE_DBC, conn, "");
if (r==SQL_SUCCESS) {
*pEnv = env;
......@@ -105,7 +105,7 @@ static int open_driver_connect(const char *connstr, SQLHENV *pEnv, SQLHDBC *pCon
SQLHDBC ConnectionHandle = conn;
SQLHWND WindowHandle = NULL;
SQLCHAR * InConnectionString = (SQLCHAR*)connstr;
SQLSMALLINT StringLength1 = strlen(connstr);
SQLSMALLINT StringLength1 = (SQLSMALLINT)strlen(connstr);
SQLCHAR * OutConnectionString = buf;
SQLSMALLINT BufferLength = sizeof(buf);
SQLSMALLINT * StringLength2Ptr = &blen;
......@@ -144,7 +144,7 @@ static int do_statement(SQLHSTMT stmt, const char *statement) {
CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
for (size_t i=0; i<cols; ++i) {
SQLLEN soi = 0;
r = SQLGetData(stmt, i+1, SQL_C_CHAR, buf, sizeof(buf), &soi);
r = SQLGetData(stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, buf, sizeof(buf), &soi);
CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "");
if (r) {
if (r!=SQL_SUCCESS_WITH_INFO) {
......@@ -185,10 +185,10 @@ static int do_insert(SQLHSTMT stmt, data_t data) {
SQLLEN lblob;
const char *statement = "insert into t values (?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
int ignored = 0;
#define ignored 0
do {
r = SQLPrepare(stmt, (SQLCHAR*)statement, strlen(statement));
r = SQLPrepare(stmt, (SQLCHAR*)statement, (SQLINTEGER)strlen(statement));
CHK_RESULT(r, SQL_HANDLE_STMT, stmt, "statement: %s", statement);
if (r) break;
......@@ -243,28 +243,30 @@ static int do_insert(SQLHSTMT stmt, data_t data) {
// r = SQLExecute(stmt);
// if (r) break;
} while (0);
#undef ignored
return r;
}
static int test1(const char *dsn, const char *uid, const char *pwd) {
SQLRETURN r = SQL_SUCCESS;
SQLHENV env = {0};
SQLHDBC conn = {0};
int n = open_connect(dsn, uid, pwd, &env, &conn);
if (n) return 1;
int ok = 0;
do {
SQLRETURN r = SQL_SUCCESS;
SQLHSTMT stmt = {0};
r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
if (r!=SQL_SUCCESS) break;
do {
if (do_statement(stmt, "drop database if exists db")) {
r = SQL_ERROR;
break;
}
for (size_t i=0; i<sizeof(pre_stmts)/sizeof(pre_stmts[0]); ++i) {
r = do_statement(stmt, pre_stmts[i]);
if (r!=SQL_SUCCESS) break;
n = do_statement(stmt, pre_stmts[i]);
if (n) break;
}
do {
data_t data = {0};
......@@ -274,7 +276,7 @@ static int test1(const char *dsn, const char *uid, const char *pwd) {
data.v2 = 32767;
data.v4 = 2147483647;
data.v8 = 9223372036854775807;
data.f4 = 123.456;
data.f4 = 123.456f;
data.f8 = 9999999.999999;
memset(data.bin, 0, sizeof(data.bin));
memset(data.blob, 0, sizeof(data.blob));
......@@ -285,8 +287,8 @@ static int test1(const char *dsn, const char *uid, const char *pwd) {
r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
if (r!=SQL_SUCCESS) break;
do {
r = do_insert(stmt, data);
if (r!=SQL_SUCCESS) break;
n = do_insert(stmt, data);
if (n) break;
} while (0);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
......@@ -297,12 +299,15 @@ static int test1(const char *dsn, const char *uid, const char *pwd) {
// if (r!=SQL_SUCCESS) break;
// } while (0);
// SQLFreeHandle(SQL_HANDLE_STMT, stmt);
ok = 1;
} while (0);
if (r!=SQL_SUCCESS) break;
if (!ok) break;
ok = 0;
for (size_t i=0; i<sizeof(pro_stmts)/sizeof(pro_stmts[0]); ++i) {
r = do_statement(stmt, pro_stmts[i]);
if (r!=SQL_SUCCESS) break;
n = do_statement(stmt, pro_stmts[i]);
if (n) break;
}
ok = 1;
} while (0);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} while (0);
......@@ -310,7 +315,7 @@ static int test1(const char *dsn, const char *uid, const char *pwd) {
SQLFreeConnect(conn);
SQLFreeEnv(env);
return r ? 1 : 0;
return ok ? 0 : 1;
}
int test_statements(const char *dsn, const char *uid, const char *pwd, const char **statements) {
......@@ -493,7 +498,7 @@ int main(int argc, char *argv[]) {
const char *connstr = (argc>4) ? argv[4] : NULL;
const char *sqls = (argc>5) ? argv[5] : NULL;
if (0) {
if (1) {
CHK_TEST(test_env());
CHK_TEST(test1(dsn, uid, pwd));
......
......@@ -24,9 +24,9 @@ extern "C" {
#include <stdbool.h>
#ifdef TAOS_ERROR_C
#define TAOS_DEFINE_ERROR(name, mod, code, msg) {.val = (0x80000000 | ((mod)<<16) | (code)), .str=(msg)},
#define TAOS_DEFINE_ERROR(name, mod, code, msg) {.val = (int32_t)((0x80000000 | ((mod)<<16) | (code))), .str=(msg)},
#else
#define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = (0x80000000 | ((mod)<<16) | (code));
#define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = (int32_t)((0x80000000 | ((mod)<<16) | (code)));
#endif
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
......
......@@ -38,14 +38,14 @@ int32_t taosGetTimestampSec();
static FORCE_INLINE int64_t taosGetTimestampMs() {
struct timeval systemTime;
gettimeofday(&systemTime, NULL);
return (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000;
return (int64_t)systemTime.tv_sec * 1000L + (int64_t)systemTime.tv_usec / 1000;
}
//@return timestamp in microsecond
static FORCE_INLINE int64_t taosGetTimestampUs() {
struct timeval systemTime;
gettimeofday(&systemTime, NULL);
return (int64_t)systemTime.tv_sec * 1000000L + (uint64_t)systemTime.tv_usec;
return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册