Skip to content

Commit 110d05c

Browse files
committed
-Weverything and whitelist warnings
1 parent 76dde0e commit 110d05c

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

ext/mysql2/client.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ void rb_mysql_client_set_active_thread(VALUE self) {
610610
const char *thr = StringValueCStr(inspect);
611611

612612
rb_raise(cMysql2Error, "This connection is in use by: %s", thr);
613-
(void)RB_GC_GUARD(inspect);
614613
}
615614
}
616615

@@ -1230,7 +1229,6 @@ void init_mysql2_client() {
12301229
}
12311230
if (lib[i] != MYSQL_LINK_VERSION[i]) {
12321231
rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_LINK_VERSION, lib);
1233-
return;
12341232
}
12351233
}
12361234
#endif
@@ -1239,7 +1237,6 @@ void init_mysql2_client() {
12391237
/* without race condition in the library */
12401238
if (mysql_library_init(0, NULL, NULL) != 0) {
12411239
rb_raise(rb_eRuntimeError, "Could not initialize MySQL client library");
1242-
return;
12431240
}
12441241

12451242
#if 0

ext/mysql2/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void rb_mysql_client_set_active_thread(VALUE self);
6666
mysql_client_wrapper *wrapper; \
6767
Data_Get_Struct(self, mysql_client_wrapper, wrapper);
6868

69-
void init_mysql2_client();
69+
void init_mysql2_client(void);
7070
void decr_mysql2_client(mysql_client_wrapper *wrapper);
7171

7272
#endif

ext/mysql2/extconf.rb

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,36 @@ def asplode(lib)
9393
end
9494

9595
# This is our wishlist. We use whichever flags work on the host.
96-
# TODO: fix statement.c and remove -Wno-declaration-after-statement
97-
# TODO: fix gperf mysql_enc_name_to_ruby.h and remove -Wno-missing-field-initializers
98-
%w(
99-
-Wall
100-
-Wextra
101-
-Werror
102-
-Wno-unused-function
103-
-Wno-declaration-after-statement
104-
-Wno-missing-field-initializers
105-
).each do |flag|
106-
$CFLAGS << ' ' << flag if try_link('int main() {return 0;}', flag)
96+
# -Wall and -Wextra are included by default.
97+
usable_flags = [
98+
'-fsanitize=address',
99+
'-fsanitize=cfi',
100+
'-fsanitize=integer',
101+
'-fsanitize=memory',
102+
'-fsanitize=thread',
103+
'-fsanitize=undefined',
104+
'-Werror',
105+
'-Weverything',
106+
'-Wno-bad-function-cast', # rb_thread_call_without_gvl returns void * that we cast to VALUE
107+
'-Wno-conditional-uninitialized', # false positive in client.c
108+
'-Wno-covered-switch-default', # result.c -- enum_field_types (when fully covered, e.g. mysql 5.5)
109+
'-Wno-declaration-after-statement', # GET_CLIENT followed by GET_STATEMENT in statement.c
110+
'-Wno-disabled-macro-expansion', # rubby :(
111+
'-Wno-documentation-unknown-command', # rubby :(
112+
'-Wno-missing-field-initializers', # gperf generates bad code
113+
'-Wno-missing-variable-declarations', # missing symbols due to ruby native ext initialization
114+
'-Wno-padded', # mysql :(
115+
'-Wno-sign-conversion', # gperf generates bad code
116+
'-Wno-static-in-inline', # gperf generates bad code
117+
'-Wno-switch-enum', # result.c -- enum_field_types (when not fully covered, e.g. mysql 5.6+)
118+
'-Wno-undef', # rubinius :(
119+
'-Wno-used-but-marked-unused', # rubby :(
120+
].select do |flag|
121+
try_link('int main() {return 0;}', flag)
107122
end
108123

124+
$CFLAGS << ' ' << usable_flags.join(' ')
125+
109126
if RUBY_PLATFORM =~ /mswin|mingw/
110127
# Build libmysql.a interface link library
111128
require 'rake'

ext/mysql2/infile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mysql2_local_infile_init(void **ptr, const char *filename, void *userdata)
5656
* < 0 error
5757
*/
5858
static int
59-
mysql2_local_infile_read(void *ptr, char *buf, uint buf_len)
59+
mysql2_local_infile_read(void *ptr, char *buf, unsigned int buf_len)
6060
{
6161
int count;
6262
mysql2_local_infile_data *data = (mysql2_local_infile_data *)ptr;
@@ -95,7 +95,7 @@ mysql2_local_infile_end(void *ptr)
9595
* Error message number (see http://dev.mysql.com/doc/refman/5.0/en/error-messages-client.html)
9696
*/
9797
static int
98-
mysql2_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
98+
mysql2_local_infile_error(void *ptr, char *error_msg, unsigned int error_msg_len)
9999
{
100100
mysql2_local_infile_data *data = (mysql2_local_infile_data *) ptr;
101101

ext/mysql2/mysql2_ext.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#ifndef MYSQL2_EXT
22
#define MYSQL2_EXT
33

4+
void Init_mysql2(void);
5+
46
/* tell rbx not to use it's caching compat layer
57
by doing this we're making a promise to RBX that
68
we'll never modify the pointers we get back from RSTRING_PTR */
79
#define RSTRING_NOT_MODIFIED
810
#include <ruby.h>
911

10-
#ifndef HAVE_UINT
11-
#define HAVE_UINT
12-
typedef unsigned short ushort;
13-
typedef unsigned int uint;
14-
#endif
15-
1612
#ifdef HAVE_MYSQL_H
1713
#include <mysql.h>
1814
#include <mysql_com.h>

ext/mysql2/result.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ static void *nogvl_stmt_fetch(void *ptr) {
159159
return (void *)r;
160160
}
161161

162-
163-
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
162+
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, int symbolize_keys) {
164163
VALUE rb_field;
165164
GET_RESULT(self);
166165

@@ -508,7 +507,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
508507
default:
509508
rb_raise(cMysql2Error, "unhandled buffer type: %d",
510509
result_buffer->buffer_type);
511-
break;
512510
}
513511
}
514512

ext/mysql2/result.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MYSQL2_RESULT_H
22
#define MYSQL2_RESULT_H
33

4-
void init_mysql2_result();
4+
void init_mysql2_result(void);
55
VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r, VALUE statement);
66

77
typedef struct {

ext/mysql2/statement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ typedef struct {
99
int refcount;
1010
} mysql_stmt_wrapper;
1111

12-
void init_mysql2_statement();
12+
void init_mysql2_statement(void);
1313
void decr_mysql2_stmt(mysql_stmt_wrapper *stmt_wrapper);
1414

1515
VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql);

0 commit comments

Comments
 (0)