Skip to content

Commit b19f6a4

Browse files
committed
CONC-329: change pvio_*_blocking to return int to accomidate SOCKET_ERROR(-1)
POWER and other architectures that define char(as my_bool) to be unsigned (as the C standard leaves this undefined). This resulted in error branches being unreachabe as indicated by the below compile warnings. plugins/pvio/pvio_socket.c:763:42: warning: comparison of constant -1 with expression of type 'my_bool' (aka 'char') is always false [-Wtautological-constant-out-of-range-compare] if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ plugins/pvio/pvio_socket.c:875:46: warning: comparison of constant -1 with expression of type 'my_bool' (aka 'char') is always false [-Wtautological-constant-out-of-range-compare] if (pvio_socket_blocking(pvio, 0, 0) == SOCKET_ERROR) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ plugins/pvio/pvio_socket.c:907:42: warning: comparison of constant -1 with expression of type 'my_bool' (aka 'char') is always false [-Wtautological-constant-out-of-range-compare] if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) ma_hext2int: signed char - prevent compiler errors when char is unsigned. libmariadb/ma_tls.c:169:31: warning: comparison of constant -1 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare] if ((d1 = ma_hex2int(*p)) == - 1 || ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~ libmariadb/ma_tls.c:170:35: warning: comparison of constant -1 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare] (d2 = ma_hex2int(*(p+1))) == -1 || ~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~ To fix this all the pvio_*_blocking functions have been changed to use int as a return value. Other my_bool/char differences fixed: mariadb_dyncol_val_str: fix prototype to use char - like implemented function. unittest: bind.is_null is my_bool* so we use a my_bool.
1 parent d3e06bc commit b19f6a4

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

include/ma_pvio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct st_ma_pvio_methods
9898
ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
9999
ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
100100
int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
101-
my_bool (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
101+
int (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
102102
my_bool (*connect)(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
103103
my_bool (*close)(MARIADB_PVIO *pvio);
104104
int (*fast_send)(MARIADB_PVIO *pvio);

include/mariadb_dyncol.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void mariadb_dyncol_free(DYNAMIC_COLUMN *str);
225225
/* conversion of values to 3 base types */
226226
enum enum_dyncol_func_result
227227
mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
228-
MARIADB_CHARSET_INFO *cs, my_bool quote);
228+
MARIADB_CHARSET_INFO *cs, char quote);
229229
enum enum_dyncol_func_result
230230
mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val);
231231
enum enum_dyncol_func_result

libmariadb/ma_pvio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
490490
my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
491491
{
492492
if (pvio && pvio->methods->blocking)
493-
return pvio->methods->blocking(pvio, block, previous_mode);
493+
return pvio->methods->blocking(pvio, block, previous_mode) != 0;
494494
return 1;
495495
}
496496
/* }}} */

libmariadb/ma_tls.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls)
130130
return tls_protocol_version[version];
131131
}
132132

133-
static char ma_hex2int(char c)
133+
static signed char ma_hex2int(char c)
134134
{
135135
if (c >= '0' && c <= '9')
136136
return c - '0';
@@ -161,7 +161,7 @@ static my_bool ma_pvio_tls_compare_fp(const char *cert_fp,
161161

162162
for(c= (char *)cert_fp; c < cert_fp + cert_fp_len; c++)
163163
{
164-
char d1, d2;
164+
signed char d1, d2;
165165
if (*p == ':')
166166
p++;
167167
if (p - fp > (int)fp_len -1)

plugins/pvio/pvio_npipe.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ssize_t pvio_npipe_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
3838
ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
3939
ssize_t pvio_npipe_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
4040
int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
41-
my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
41+
int pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
4242
my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
4343
my_bool pvio_npipe_close(MARIADB_PVIO *pvio);
4444
int pvio_npipe_fast_send(MARIADB_PVIO *pvio);
@@ -187,7 +187,7 @@ int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeo
187187
return -1;
188188
}
189189

190-
my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
190+
int pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
191191
{
192192
/* not supported */
193193
DWORD flags= 0;

plugins/pvio/pvio_shmem.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int pvio_shm_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
3636
ssize_t pvio_shm_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
3737
ssize_t pvio_shm_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
3838
int pvio_shm_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
39-
my_bool pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
39+
int pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
4040
my_bool pvio_shm_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
4141
my_bool pvio_shm_close(MARIADB_PVIO *pvio);
4242
int pvio_shm_shutdown(MARIADB_PVIO *pvio);
@@ -218,7 +218,7 @@ int pvio_shm_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout
218218
return 0;
219219
}
220220

221-
my_bool pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
221+
int pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
222222
{
223223
/* not supported */
224224
return 0;

plugins/pvio/pvio_socket.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ssize_t pvio_socket_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
9292
ssize_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
9393
ssize_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
9494
int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
95-
my_bool pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
95+
int pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
9696
my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
9797
my_bool pvio_socket_close(MARIADB_PVIO *pvio);
9898
int pvio_socket_fast_send(MARIADB_PVIO *pvio);
@@ -565,7 +565,7 @@ int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int time
565565
return rc;
566566
}
567567

568-
my_bool pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
568+
int pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
569569
{
570570
my_bool is_blocking;
571571
struct st_pvio_socket *csock;

unittest/libmariadb/ps.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ static int test_bind_negative(MYSQL *mysql)
22092209
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
22102210
my_bind[0].buffer= (void *)&my_val;
22112211
my_bind[0].length= &my_length;
2212-
my_bind[0].is_null= (char*)&my_null;
2212+
my_bind[0].is_null= &my_null;
22132213

22142214
rc= mysql_stmt_bind_param(stmt, my_bind);
22152215
check_stmt_rc(rc, stmt);
@@ -2400,12 +2400,12 @@ static int test_union_param(MYSQL *mysql)
24002400
my_bind[0].buffer= (char*) &my_val;
24012401
my_bind[0].buffer_length= 4;
24022402
my_bind[0].length= &my_length;
2403-
my_bind[0].is_null= (char*)&my_null;
2403+
my_bind[0].is_null= &my_null;
24042404
my_bind[1].buffer_type= MYSQL_TYPE_STRING;
24052405
my_bind[1].buffer= (char*) &my_val;
24062406
my_bind[1].buffer_length= 4;
24072407
my_bind[1].length= &my_length;
2408-
my_bind[1].is_null= (char*)&my_null;
2408+
my_bind[1].is_null= &my_null;
24092409

24102410
rc= mysql_stmt_bind_param(stmt, my_bind);
24112411
check_stmt_rc(rc, stmt);
@@ -3313,7 +3313,7 @@ ENGINE=InnoDB DEFAULT CHARSET=utf8");
33133313
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
33143314
my_bind[0].buffer= (void *)&my_val;
33153315
my_bind[0].length= &my_length;
3316-
my_bind[0].is_null= (char*)&my_null;
3316+
my_bind[0].is_null= &my_null;
33173317
my_val= 1;
33183318
rc= mysql_stmt_bind_param(stmt, my_bind);
33193319
check_stmt_rc(rc, stmt);

unittest/libmariadb/view.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int test_view(MYSQL *mysql)
3030
MYSQL_BIND my_bind[1];
3131
char str_data[50];
3232
ulong length = 0L;
33-
long is_null = 0L;
33+
my_bool is_null = 0;
3434
const char *query=
3535
"SELECT COUNT(*) FROM v1 WHERE SERVERNAME=?";
3636

@@ -84,7 +84,7 @@ static int test_view(MYSQL *mysql)
8484
my_bind[0].buffer_length= 50;
8585
my_bind[0].length= &length;
8686
length= 4;
87-
my_bind[0].is_null= (char*)&is_null;
87+
my_bind[0].is_null= &is_null;
8888
rc= mysql_stmt_bind_param(stmt, my_bind);
8989
check_stmt_rc(rc, stmt);
9090

@@ -301,7 +301,7 @@ static int test_view_insert(MYSQL *mysql)
301301
MYSQL_BIND my_bind[1];
302302
int my_val = 0;
303303
ulong my_length = 0L;
304-
long my_null = 0L;
304+
my_bool my_null = 0;
305305
const char *query=
306306
"insert into v1 values (?)";
307307

@@ -328,7 +328,7 @@ static int test_view_insert(MYSQL *mysql)
328328
my_bind[0].buffer_type = MYSQL_TYPE_LONG;
329329
my_bind[0].buffer = (char *)&my_val;
330330
my_bind[0].length = &my_length;
331-
my_bind[0].is_null = (char*)&my_null;
331+
my_bind[0].is_null = &my_null;
332332
rc= mysql_stmt_bind_param(insert_stmt, my_bind);
333333
check_stmt_rc(rc, select_stmt);
334334

0 commit comments

Comments
 (0)