From 895dcb61e30ff187d2b152acb352cd7cdb06ed60 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 4 Jun 2020 16:49:21 +0200 Subject: [PATCH] C preprocessor defines fix --- include/ma_common.h | 4 +- include/ma_global.h | 30 ++++++------ include/ma_list.h | 2 +- include/ma_sys.h | 36 +++++++++----- include/mariadb_com.h | 8 ++-- include/mariadb_dyncol.h | 5 +- include/mariadb_stmt.h | 8 ++-- include/mysql.h | 8 ++-- libmariadb/ma_dtoa.c | 18 +++---- libmariadb/ma_stmt_codec.c | 2 +- libmariadb/mariadb_async.c | 4 +- libmariadb/mariadb_stmt.c | 2 +- libmariadb/secure/ma_schannel.c | 2 +- plugins/auth/sspi_common.h | 2 +- plugins/connection/replication.c | 8 ++-- plugins/pvio/pvio_shmem.c | 2 +- plugins/pvio/pvio_socket.c | 2 +- plugins/trace/trace_example.c | 2 +- unittest/libmariadb/connection.c | 34 ++++++------- unittest/libmariadb/cursor.c | 2 +- unittest/libmariadb/my_test.h | 82 +++++++++++++++++++------------- unittest/libmariadb/ps.c | 18 +++---- unittest/libmariadb/ps_bugs.c | 30 ++++++------ unittest/libmariadb/result.c | 18 +++---- 24 files changed, 179 insertions(+), 150 deletions(-) diff --git a/include/ma_common.h b/include/ma_common.h index 123a5104..62cf71cc 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -109,8 +109,8 @@ struct st_mariadb_extension { }; #define OPT_EXT_VAL(a,key) \ - ((a)->options.extension && (a)->options.extension->key) ?\ - (a)->options.extension->key : 0 + (((a)->options.extension && (a)->options.extension->key) ?\ + (a)->options.extension->key : 0) #endif diff --git a/include/ma_global.h b/include/ma_global.h index 0b93f7f4..ee74ffae 100644 --- a/include/ma_global.h +++ b/include/ma_global.h @@ -250,7 +250,7 @@ double my_ulonglong2double(unsigned long long A); #if defined(_lint) || defined(FORCE_INIT_OF_VARS) -#define LINT_INIT(var) var=0 /* No uninitialize-warning */ +#define LINT_INIT(var) do{var=0;}while(0) /* No uninitialize-warning */ #define LINT_INIT_STRUCT(var) memset(&var, 0, sizeof(var)) /* No uninitialize-warning */ #else #define LINT_INIT(var) @@ -272,10 +272,10 @@ typedef unsigned short ushort; #endif #define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0) -#define swap(t,a,b) { register t dummy; dummy = a; a = b; b = dummy; } +#define swap(t,a,b) do{register t dummy; dummy = a; a = b; b = dummy;}while(0) #define test(a) ((a) ? 1 : 0) -#define set_if_bigger(a,b) { if ((a) < (b)) (a)=(b); } -#define set_if_smaller(a,b) { if ((a) > (b)) (a)=(b); } +#define set_if_bigger(a,b) do{ if ((a) < (b)) (a)=(b); }while(0) +#define set_if_smaller(a,b) do{ if ((a) > (b)) (a)=(b); }while(0) #define test_all_bits(a,b) (((a) & (b)) == (b)) #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1)) #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) @@ -440,11 +440,11 @@ typedef SOCKET_SIZE_TYPE size_socket; */ #define MALLOC_OVERHEAD 8 /* get memory in huncs */ -#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD) +#define ONCE_ALLOC_INIT ((uint) (4096-MALLOC_OVERHEAD)) /* Typical record cash */ -#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD) +#define RECORD_CACHE_SIZE ((uint) (64*1024-MALLOC_OVERHEAD)) /* Typical key cash */ -#define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD) +#define KEY_CACHE_SIZE ((uint) (8*1024*1024-MALLOC_OVERHEAD)) /* Some things that this system doesn't have */ @@ -815,7 +815,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ *((T)+3)=(uchar) (((A) >> 24)); \ *((T)+4)=(uchar) (((A) >> 32)); \ *((T)+5)=(uchar) (((A) >> 40)); } while(0) -#define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A) +#define int8store(T,A) do {*((ulonglong *) (T))= (ulonglong) (A);} while(0) typedef union { double v; @@ -1046,11 +1046,11 @@ do { doubleget_union _tmp; \ #endif /* WORDS_BIGENDIAN */ #ifndef THREAD -#define thread_safe_increment(V,L) (V)++ -#define thread_safe_add(V,C,L) (V)+=(C) -#define thread_safe_sub(V,C,L) (V)-=(C) -#define statistic_increment(V,L) (V)++ -#define statistic_add(V,C,L) (V)+=(C) +#define thread_safe_increment(V,L) ((V)++) +#define thread_safe_add(V,C,L) ((V)+=(C)) +#define thread_safe_sub(V,C,L) ((V)-=(C)) +#define statistic_increment(V,L) ((V)++) +#define statistic_add(V,C,L) ((V)+=(C)) #endif #ifdef _WIN32 @@ -1069,9 +1069,9 @@ do { doubleget_union _tmp; \ #ifdef HAVE_DLOPEN #ifdef _WIN32 -#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name) +#define dlsym(lib, name) GetProcAddress((HMODULE)(lib), name) #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) -#define dlclose(lib) FreeLibrary((HMODULE)lib) +#define dlclose(lib) FreeLibrary((HMODULE)(lib)) #elif defined(HAVE_DLFCN_H) #include #endif diff --git a/include/ma_list.h b/include/ma_list.h index 549280d6..ccd2bbd8 100644 --- a/include/ma_list.h +++ b/include/ma_list.h @@ -39,7 +39,7 @@ extern int list_walk(LIST *list,list_walk_action action,char * argument); #define list_rest(a) ((a)->next) #define list_push(a,b) (a)=list_cons((b),(a)) -#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); } +#define list_pop(A) do {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); } while(0) #ifdef __cplusplus } diff --git a/include/ma_sys.h b/include/ma_sys.h index 45654b3f..ecb6fccb 100644 --- a/include/ma_sys.h +++ b/include/ma_sys.h @@ -35,9 +35,21 @@ typedef struct my_aio_result { #include -#define MYSYS_PROGRAM_USES_CURSES() { ma_error_handler_hook = ma_message_curses; mysys_uses_curses=1; } -#define MYSYS_PROGRAM_DONT_USE_CURSES() { ma_error_handler_hook = ma_message_no_curses; mysys_uses_curses=0;} -#define MY_INIT(name); { ma_progname= name; ma_init(); } +#define MYSYS_PROGRAM_USES_CURSES() \ +do {\ + ma_error_handler_hook = ma_message_curses;\ + mysys_uses_curses=1;\ +} while(0) +#define MYSYS_PROGRAM_DONT_USE_CURSES() \ +do {\ + ma_error_handler_hook = ma_message_no_curses; \ + mysys_uses_curses=0; \ +} while(0) +#define MY_INIT(name) \ +do {\ + ma_progname= name;\ + ma_init();\ +} while(0) #define MAXMAPS (4) /* Number of error message maps */ #define ERRMOD (1000) /* Max number of errors in a map */ @@ -285,15 +297,15 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *); /* defines for mf_iocache */ /* Test if buffer is inited */ -#define my_b_clear(info) (info)->buffer=0 -#define my_b_inited(info) (info)->buffer +#define my_b_clear(info) do{(info)->buffer= 0;} while (0) +#define my_b_inited(info) ((info)->buffer) #define my_b_EOF INT_MIN #define my_b_read(info,Buffer,Count) \ ((info)->rc_pos + (Count) <= (info)->rc_end ?\ - (memcpy(Buffer,(info)->rc_pos,(size_t) (Count)), \ + (memcpy((Buffer),(info)->rc_pos,(size_t) (Count)), \ ((info)->rc_pos+=(Count)),0) :\ - (*(info)->read_function)((info),Buffer,Count)) + (*(info)->read_function)((info),(Buffer),(Count))) #define my_b_get(info) \ ((info)->rc_pos != (info)->rc_end ?\ @@ -302,18 +314,18 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *); #define my_b_write(info,Buffer,Count) \ ((info)->rc_pos + (Count) <= (info)->rc_end ?\ - (memcpy((info)->rc_pos,Buffer,(size_t) (Count)), \ + (memcpy((info)->rc_pos,(Buffer),(size_t) (Count)), \ ((info)->rc_pos+=(Count)),0) :\ - _my_b_write(info,Buffer,Count)) + _my_b_write((info),(Buffer),(Count))) /* my_b_write_byte doesn't have any err-check */ #define my_b_write_byte(info,chr) \ (((info)->rc_pos < (info)->rc_end) ?\ ((*(info)->rc_pos++)=(chr)) :\ - (_my_b_write(info,0,0) , ((*(info)->rc_pos++)=(chr)))) + (_my_b_write((info),0,0) , ((*(info)->rc_pos++)=(chr)))) #define my_b_fill_cache(info) \ - (((info)->rc_end=(info)->rc_pos),(*(info)->read_function)(info,0,0)) + (((info)->rc_end=(info)->rc_pos),(*(info)->read_function)((info),0,0)) #define my_b_tell(info) ((info)->pos_in_file + \ ((info)->rc_pos - (info)->rc_request_pos)) @@ -401,7 +413,7 @@ extern void casedn_str(my_string str); extern void case_sort(my_string str,uint length); extern uint ma_dirname_part(my_string to,const char *name); extern uint ma_dirname_length(const char *name); -#define base_name(A) (A+dirname_length(A)) +#define base_name(A) ((A)+dirname_length(A)) extern int test_if_hard_path(const char *dir_name); extern char *ma_convert_dirname(my_string name); extern void to_unix_path(my_string name); diff --git a/include/mariadb_com.h b/include/mariadb_com.h index c63e5b06..7e722a0b 100644 --- a/include/mariadb_com.h +++ b/include/mariadb_com.h @@ -34,7 +34,7 @@ #define HOSTNAME_LENGTH 60 #define SYSTEM_MB_MAX_CHAR_LENGTH 4 #define USERNAME_CHAR_LENGTH 128 -#define USERNAME_LENGTH USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH +#define USERNAME_LENGTH (USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH) #define SERVER_VERSION_LENGTH 60 #define SQLSTATE_LENGTH 5 #define SCRAMBLE_LENGTH 20 @@ -174,7 +174,7 @@ enum enum_server_command #define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35) #define IS_MARIADB_EXTENDED_SERVER(mysql)\ - !(mysql->server_capabilities & CLIENT_MYSQL) + (!(mysql->server_capabilities & CLIENT_MYSQL)) #define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ MARIADB_CLIENT_COM_MULTI |\ @@ -239,7 +239,7 @@ enum enum_server_command #define MYSQL_ERRMSG_SIZE 512 #define NET_READ_TIMEOUT 30 /* Timeout on read */ #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ -#define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ +#define NET_WAIT_TIMEOUT (8*60*60) /* Wait for new query */ /* for server integration (mysqlbinlog) */ #define LIST_PROCESS_HOST_LEN 64 @@ -316,7 +316,7 @@ enum enum_session_state_type #define SESSION_TRACK_BEGIN 0 #define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_TYPE -#define SESSION_TRACK_TYPES SESSION_TRACK_END + 1 +#define SESSION_TRACK_TYPES (SESSION_TRACK_END + 1) enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, diff --git a/include/mariadb_dyncol.h b/include/mariadb_dyncol.h index a6084fd9..216431a8 100644 --- a/include/mariadb_dyncol.h +++ b/include/mariadb_dyncol.h @@ -242,7 +242,10 @@ int mariadb_dyncol_column_cmp_named(const MYSQL_LEX_STRING *s1, enum enum_dyncol_func_result mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count); -#define mariadb_dyncol_value_init(V) (V)->type= DYN_COL_NULL +#define mariadb_dyncol_value_init(V) \ +do {\ + (V)->type= DYN_COL_NULL;\ +} while(0) /* Prepare value for using as decimal diff --git a/include/mariadb_stmt.h b/include/mariadb_stmt.h index 0aa14362..d07540ea 100644 --- a/include/mariadb_stmt.h +++ b/include/mariadb_stmt.h @@ -35,20 +35,20 @@ (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))) #define SET_CLIENT_STMT_ERROR(a, b, c, d) \ -{ \ +do { \ (a)->last_errno= (b);\ strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\ (a)->sqlstate[SQLSTATE_LENGTH]= 0;\ strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE);\ (a)->last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\ -} +} while (0) #define CLEAR_CLIENT_STMT_ERROR(a) \ -{ \ +do { \ (a)->last_errno= 0;\ strcpy((a)->sqlstate, "00000");\ (a)->last_error[0]= 0;\ -} +} while (0) #define MYSQL_PS_SKIP_RESULT_W_LEN -1 #define MYSQL_PS_SKIP_RESULT_STR -2 diff --git a/include/mysql.h b/include/mysql.h index a160de0a..17aab5ea 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -130,13 +130,13 @@ extern unsigned int mariadb_deinitialize_ssl; typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ #define SET_CLIENT_ERROR(a, b, c, d) \ - { \ + do { \ (a)->net.last_errno= (b);\ strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\ (a)->net.sqlstate[SQLSTATE_LENGTH]= 0;\ strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\ (a)->net.last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\ - } + } while(0) /* For mysql_async.c */ #define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) @@ -144,12 +144,12 @@ extern const char *SQLSTATE_UNKNOWN; #define unknown_sqlstate SQLSTATE_UNKNOWN #define CLEAR_CLIENT_ERROR(a) \ - { \ + do { \ (a)->net.last_errno= 0;\ strcpy((a)->net.sqlstate, "00000");\ (a)->net.last_error[0]= '\0';\ (a)->net.extension->extended_errno= 0;\ - } + } while (0) #define MYSQL_COUNT_ERROR (~(unsigned long long) 0) diff --git a/libmariadb/ma_dtoa.c b/libmariadb/ma_dtoa.c index 1136bfee..8fdff6b8 100644 --- a/libmariadb/ma_dtoa.c +++ b/libmariadb/ma_dtoa.c @@ -514,14 +514,14 @@ typedef union { double d; ULong L[2]; } U; #if defined(HAVE_BIGENDIAN) || defined(WORDS_BIGENDIAN) || \ (defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)) -#define word0(x) (x)->L[0] -#define word1(x) (x)->L[1] +#define word0(x) ((x)->L[0]) +#define word1(x) ((x)->L[1]) #else -#define word0(x) (x)->L[1] -#define word1(x) (x)->L[0] +#define word0(x) ((x)->L[1]) +#define word1(x) ((x)->L[0]) #endif -#define dval(x) (x)->d +#define dval(x) ((x)->d) /* #define P DBL_MANT_DIG */ /* Ten_pmax= floor(P*log(2)/log(5)) */ @@ -568,8 +568,8 @@ typedef union { double d; ULong L[2]; } U; #define Rounding Flt_Rounds #endif -#define rounded_product(a,b) a*= b -#define rounded_quotient(a,b) a/= b +#define rounded_product(a,b) ((a)*= (b)) +#define rounded_quotient(a,b) ((a)/= (b)) #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) #define Big1 0xffffffff @@ -579,8 +579,8 @@ typedef union { double d; ULong L[2]; } U; #define Kmax 15 -#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ - 2*sizeof(int) + y->wds*sizeof(ULong)) +#define Bcopy(x,y) memcpy((char *)&(x)->sign, (char *)&(y)->sign, \ + 2*sizeof(int) + (y)->wds*sizeof(ULong)) /* Arbitrary-length integer */ diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index d38fbd25..06a4bcc0 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -73,7 +73,7 @@ #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL) #endif -#define MAX_DBL_STR 3 + DBL_MANT_DIG - DBL_MIN_EXP +#define MAX_DBL_STR (3 + DBL_MANT_DIG - DBL_MIN_EXP) #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX) /* First check for ANSI C99 definition: */ diff --git a/libmariadb/mariadb_async.c b/libmariadb/mariadb_async.c index 6d607cdb..feb2ce2a 100644 --- a/libmariadb/mariadb_async.c +++ b/libmariadb/mariadb_async.c @@ -40,10 +40,10 @@ Windows does not support MSG_DONTWAIT for send()/recv(). So we need to ensure that the socket is non-blocking at the start of every operation. */ -#define WIN_SET_NONBLOCKING(mysql) { \ +#define WIN_SET_NONBLOCKING(mysql) do { \ my_bool old_mode; \ if ((mysql)->net.pvio) ma_pvio_blocking((mysql)->net.pvio, FALSE, &old_mode); \ - } + } while(0) #else #define WIN_SET_NONBLOCKING(mysql) #endif diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index 433e4954..8f5bddcf 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -61,7 +61,7 @@ #define UPDATE_STMT_ERROR(stmt)\ SET_CLIENT_STMT_ERROR((stmt), (stmt)->mysql->net.last_errno, (stmt)->mysql->net.sqlstate, (stmt)->mysql->net.last_error) -#define STMT_NUM_OFS(type, a,r) ((type *)(a))[r] +#define STMT_NUM_OFS(type, a, r) (((type *)(a))[r]) #define MADB_RESET_ERROR 1 #define MADB_RESET_LONGDATA 2 #define MADB_RESET_SERVER 4 diff --git a/libmariadb/secure/ma_schannel.c b/libmariadb/secure/ma_schannel.c index ffc307ca..e989aeaa 100644 --- a/libmariadb/secure/ma_schannel.c +++ b/libmariadb/secure/ma_schannel.c @@ -26,7 +26,7 @@ #define SC_IO_BUFFER_SIZE 0x4000 #define MAX_SSL_ERR_LEN 100 -#define SCHANNEL_PAYLOAD(A) (A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer +#define SCHANNEL_PAYLOAD(A) ((A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer) void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo); diff --git a/plugins/auth/sspi_common.h b/plugins/auth/sspi_common.h index 5538f76e..da9159eb 100644 --- a/plugins/auth/sspi_common.h +++ b/plugins/auth/sspi_common.h @@ -34,5 +34,5 @@ POSSIBILITY OF SUCH DAMAGE. #include #define SSPI_MAX_TOKEN_SIZE 50000 -#define SEC_ERROR(err) (err < 0) +#define SEC_ERROR(err) ((err) < 0) extern void sspi_errmsg(int err, char *buf, size_t size); diff --git a/plugins/connection/replication.c b/plugins/connection/replication.c index 11729532..0e7a18b7 100644 --- a/plugins/connection/replication.c +++ b/plugins/connection/replication.c @@ -85,16 +85,16 @@ typedef struct st_conn_repl { } REPL_DATA; #define SET_SLAVE(mysql, data)\ -{\ +do {\ mysql->net.pvio= data->pvio[MARIADB_SLAVE]; \ data->current_type= MARIADB_SLAVE;\ -} +} while(0) #define SET_MASTER(mysql, data)\ -{\ +do {\ mysql->net.pvio= data->pvio[MARIADB_MASTER];\ data->current_type= MARIADB_MASTER;\ -} +} while(0) /* parse url diff --git a/plugins/pvio/pvio_shmem.c b/plugins/pvio/pvio_shmem.c index 355b2ba6..f412393b 100644 --- a/plugins/pvio/pvio_shmem.c +++ b/plugins/pvio/pvio_shmem.c @@ -29,7 +29,7 @@ #include #include -#define PVIO_SHM_BUFFER_SIZE 16000 + 4 +#define PVIO_SHM_BUFFER_SIZE (16000 + 4) my_bool pvio_shm_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); int pvio_shm_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 8106b348..0d725bab 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -52,7 +52,7 @@ #include #include #include -#define IS_SOCKET_EINTR(err) (err == SOCKET_EINTR) +#define IS_SOCKET_EINTR(err) ((err) == SOCKET_EINTR) #else #include #define O_NONBLOCK 1 diff --git a/plugins/trace/trace_example.c b/plugins/trace/trace_example.c index f4bdae90..93b1e55e 100644 --- a/plugins/trace/trace_example.c +++ b/plugins/trace/trace_example.c @@ -116,7 +116,7 @@ typedef struct { unsigned long pkt_length; } TRACE_INFO; -#define TRACE_STATUS(a) (!a) ? "ok" : "error" +#define TRACE_STATUS(a) ((!a) ? "ok" : "error") TRACE_INFO *trace_info= NULL; diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index 654d0acf..933d27cf 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -223,11 +223,11 @@ static int test_change_user(MYSQL *mysql) /* Prepare environment */ sprintf(buff, "drop database if exists %s", db); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sprintf(buff, "create database %s", db); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sprintf(buff, "grant select on %s.* to %s@'%%' identified by '%s'", @@ -235,14 +235,14 @@ static int test_change_user(MYSQL *mysql) user_pw, pw); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sprintf(buff, "grant select on %s.* to %s@'%%'", db, user_no_pw); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); /* Try some combinations */ @@ -288,13 +288,13 @@ static int test_change_user(MYSQL *mysql) FAIL_UNLESS(rc, "Error expected"); rc= mysql_change_user(mysql, user_pw, pw, db); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_pw, pw, NULL); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_pw, pw, ""); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_no_pw, pw, db); FAIL_UNLESS(rc, "Error expected"); @@ -306,16 +306,16 @@ static int test_change_user(MYSQL *mysql) FAIL_UNLESS(rc, "Error expected"); rc= mysql_change_user(mysql, user_no_pw, "", NULL); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_no_pw, "", ""); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_no_pw, "", db); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, user_no_pw, NULL, db); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_change_user(mysql, "", pw, db); FAIL_UNLESS(rc, "Error expected"); @@ -345,15 +345,15 @@ static int test_change_user(MYSQL *mysql) sprintf(buff, "drop database %s", db); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sprintf(buff, "drop user %s@'%%'", user_pw); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sprintf(buff, "drop user %s@'%%'", user_no_pw); rc= mysql_query(mysql, buff); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); return OK; } @@ -661,7 +661,7 @@ int test_connection_timeout(MYSQL *unused __attribute__((unused))) elapsed= time(NULL) - start; diag("elapsed: %lu", (unsigned long)elapsed); mysql_close(mysql); - FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored") + FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored"); return OK; } @@ -681,7 +681,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused))) elapsed= time(NULL) - start; diag("elapsed: %lu", (unsigned long)elapsed); mysql_close(mysql); - FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored") + FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored"); return OK; } @@ -706,7 +706,7 @@ int test_connection_timeout3(MYSQL *unused __attribute__((unused))) } elapsed= time(NULL) - start; diag("elapsed: %lu", (unsigned long)elapsed); - FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored") + FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored"); mysql_close(mysql); mysql= mysql_init(NULL); diff --git a/unittest/libmariadb/cursor.c b/unittest/libmariadb/cursor.c index 74a53aa0..6eb2fcdc 100644 --- a/unittest/libmariadb/cursor.c +++ b/unittest/libmariadb/cursor.c @@ -1123,7 +1123,7 @@ static int test_bug11909(MYSQL *mysql) check_stmt_rc(rc, stmt2); rc= mysql_stmt_fetch(stmt2); - FAIL_UNLESS(rc == 0, "rc != 0") + FAIL_UNLESS(rc == 0, "rc != 0"); FAIL_UNLESS(empno == 10, "empno != 10"); FAIL_UNLESS(strcmp(firstname, "CHRISTINE""") == 0, "firstname != 'Christine'"); diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index f7cf9464..e0f3d078 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -64,57 +64,71 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ /* prevent warnings on Win64 by using STMT_LEN instead of strlen */ -#define STMT_LEN(A) (unsigned long)strlen((A)) +#define STMT_LEN(A) ((unsigned long)strlen((A))) #define SKIP_TRAVIS()\ -if (getenv("TRAVIS"))\ -{\ - diag("Skip test on Travis CI");\ - return SKIP;\ -} +do {\ + if (getenv("TRAVIS"))\ + {\ + diag("Skip test on Travis CI");\ + return SKIP;\ + }\ +}while(0) #define SKIP_MYSQL(mysql)\ -if (!mariadb_connection(mysql))\ -{\ - diag("Skip test for non MariaDB server");\ - return OK;\ -} +do {\ + if (!mariadb_connection(mysql))\ + {\ + diag("Skip test for non MariaDB server");\ + return OK;\ + }\ +} while(0) #define check_mysql_rc(rc, mysql) \ -if (rc)\ -{\ - diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \ - mysql_errno(mysql), __FILE__, __LINE__);\ - return(FAIL);\ -} +do {\ + if (rc)\ + {\ + diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \ + mysql_errno(mysql), __FILE__, __LINE__);\ + return(FAIL);\ + }\ +} while(0) #define check_stmt_rc(rc, stmt) \ -if (rc)\ -{\ - diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\ - return(FAIL);\ -} +do {\ + if (rc)\ + {\ + diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\ + return(FAIL);\ + }\ +} while(0) #define FAIL_IF(expr, reason)\ -if (expr)\ -{\ - diag("Error: %s (%s: %d)", (reason) ? reason : "", __FILE__, __LINE__);\ - return FAIL;\ -} +do {\ + if (expr)\ + {\ + diag("Error: %s (%s: %d)", (reason) ? reason : "", __FILE__, __LINE__);\ + return FAIL;\ + }\ +} while(0) #define FAIL_UNLESS(expr, reason)\ -if (!(expr))\ -{\ - diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\ - return FAIL;\ -} +do {\ + if (!(expr))\ + {\ + diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\ + return FAIL;\ + }\ +} while(0) #define SKIP_CONNECTION_HANDLER \ - if (hostname && strstr(hostname, "://"))\ +do {\ + if (hostname && strstr(hostname, "://"))\ {\ diag("Test skipped (connection handler)");\ return SKIP;\ - } + }\ +} while(0) /* connection options */ #define TEST_CONNECTION_DEFAULT 1 /* default connection */ diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 423cd4a8..d5ed10c1 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -678,7 +678,7 @@ static int test_prepare_ext(MYSQL *mysql) char query[MAX_TEST_QUERY_LENGTH]; rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); sql= (char *)"CREATE TABLE test_prepare_ext" "(" @@ -716,7 +716,7 @@ static int test_prepare_ext(MYSQL *mysql) " c32 set('monday', 'tuesday', 'wednesday'))"; rc= mysql_query(mysql, sql); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); /* insert by prepare - all integers */ strcpy(query, "INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)"); @@ -785,7 +785,7 @@ static int test_prepare_ext(MYSQL *mysql) mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); return OK; } @@ -1203,7 +1203,7 @@ static int test_long_data(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 3, "Paramcount != 3"); @@ -1296,7 +1296,7 @@ static int test_long_data_str(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); @@ -1395,7 +1395,7 @@ static int test_long_data_str1(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); @@ -1465,7 +1465,7 @@ static int test_long_data_str1(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0"); @@ -1560,7 +1560,7 @@ static int test_long_data_bin(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); @@ -1653,7 +1653,7 @@ static int test_simple_delete(MYSQL *mysql) stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, SL(query)); - check_stmt_rc(rc, stmt) + check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index aa8eabf7..25fd9f52 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -1064,10 +1064,10 @@ static int test_bug1946(MYSQL *mysql) rc= mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE prepare_command(ID INT)"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); @@ -1106,9 +1106,9 @@ static int test_bug20152(MYSQL *mysql) tm.second = 42; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, SL(query)); @@ -1120,7 +1120,7 @@ static int test_bug20152(MYSQL *mysql) rc= mysql_stmt_close(stmt); check_stmt_rc(rc, stmt); rc= mysql_query(mysql, "DROP TABLE t1"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); FAIL_UNLESS(tm.hour == 14 && tm.minute == 9 && tm.second == 42, "time != 14:09:42"); return OK; } @@ -1142,10 +1142,10 @@ static int test_bug2247(MYSQL *mysql) /* create table and insert few rows */ rc= mysql_query(mysql, drop); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, create); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); @@ -1160,7 +1160,7 @@ static int test_bug2247(MYSQL *mysql) FAIL_UNLESS(exp_count == 1, "exp_count != 1"); rc= mysql_query(mysql, SELECT); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); /* mysql_store_result overwrites mysql->affected_rows. Check that mysql_stmt_affected_rows() returns the same value, whereas @@ -1173,7 +1173,7 @@ static int test_bug2247(MYSQL *mysql) FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); rc= mysql_query(mysql, update); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS"); FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); @@ -1192,13 +1192,13 @@ static int test_bug2247(MYSQL *mysql) FAIL_UNLESS(exp_count == NUM_ROWS, "exp_count != NUM_ROWS"); rc= mysql_query(mysql, insert); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); FAIL_UNLESS(mysql_affected_rows(mysql) == 1, "affected_rows != 1"); FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); mysql_stmt_close(stmt); rc= mysql_query(mysql, drop); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); return OK; } @@ -1215,10 +1215,10 @@ static int test_bug2248(MYSQL *mysql) rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); @@ -1256,7 +1256,7 @@ static int test_bug2248(MYSQL *mysql) mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE test_bug2248"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); return OK; } @@ -2658,7 +2658,7 @@ static int test_bug5194(MYSQL *mysql) MAX_PARAM_COUNT * CHARS_PER_PARAM + 1); param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM); - FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory") + FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory"); stmt= mysql_stmt_init(mysql); diff --git a/unittest/libmariadb/result.c b/unittest/libmariadb/result.c index 23f6b4e7..c18d6059 100644 --- a/unittest/libmariadb/result.c +++ b/unittest/libmariadb/result.c @@ -541,16 +541,16 @@ static int test_bug19671(MYSQL *mysql) mysql_query(mysql, "set sql_mode=''"); rc= mysql_query(mysql, "drop table if exists t1"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "drop view if exists v1"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t1(f1 int)"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create view v1 as select va.* from t1 va"); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); result= mysql_list_fields(mysql, "v1", NULL); FAIL_IF(!result, "Invalid result set"); @@ -568,8 +568,8 @@ static int test_bug19671(MYSQL *mysql) } mysql_free_result(result); - check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql) - check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql) + check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql); + check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql); return OK; } @@ -604,17 +604,17 @@ static int test_bug21726(MYSQL *mysql) check_mysql_rc(rc, mysql); rc= mysql_query(mysql, update_query); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); insert_id= mysql_insert_id(mysql); FAIL_UNLESS(insert_id == 2, "insert_id != 2"); rc= mysql_query(mysql, update_query); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); insert_id= mysql_insert_id(mysql); FAIL_UNLESS(insert_id == 3, "insert_id != 3"); rc= mysql_query(mysql, select_query); - check_mysql_rc(rc, mysql) + check_mysql_rc(rc, mysql); insert_id= mysql_insert_id(mysql); FAIL_UNLESS(insert_id == 3, "insert_id != 3"); result= mysql_store_result(mysql);