diff options
author | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2010-06-10 17:16:43 -0300 |
---|---|---|
committer | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2010-06-10 17:16:43 -0300 |
commit | 6f3a540c37bd1d84139c32a4b74844ff648c3b0c (patch) | |
tree | 7bea8c8add0bd07fdf1275ad174a131e1f08d6d1 /mysys | |
parent | a24df71e95fb6379a3ba86322c9941a82b8d6527 (diff) | |
download | mariadb-git-6f3a540c37bd1d84139c32a4b74844ff648c3b0c.tar.gz |
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/mf_wfile.c | 2 | ||||
-rw-r--r-- | mysys/my_getopt.c | 36 |
2 files changed, 18 insertions, 20 deletions
diff --git a/mysys/mf_wfile.c b/mysys/mf_wfile.c index f98d348994e..4a4fb466600 100644 --- a/mysys/mf_wfile.c +++ b/mysys/mf_wfile.c @@ -119,6 +119,6 @@ void wf_end(WF_PACK *buffer) { DBUG_ENTER("wf_end"); if (buffer) - my_free((uchar*) buffer,MYF(0)); + my_free(buffer, MYF(0)); DBUG_VOID_RETURN; } /* wf_end */ diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index fc5662812b0..26b1cc75af0 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -22,7 +22,7 @@ #include <errno.h> #include <m_string.h> -typedef void (*init_func_p)(const struct my_option *option, uchar* *variable, +typedef void (*init_func_p)(const struct my_option *option, void *variable, longlong value); static void default_reporter(enum loglevel level, const char *format, ...); @@ -40,11 +40,11 @@ static ulonglong getopt_ull(char *arg, const struct my_option *optp, static double getopt_double(char *arg, const struct my_option *optp, int *err); static void init_variables(const struct my_option *options, init_func_p init_one_value); -static void init_one_value(const struct my_option *option, uchar* *variable, +static void init_one_value(const struct my_option *option, void *variable, longlong value); -static void fini_one_value(const struct my_option *option, uchar* *variable, +static void fini_one_value(const struct my_option *option, void *variable, longlong value); -static int setval(const struct my_option *opts, uchar* *value, char *argument, +static int setval(const struct my_option *opts, void *value, char *argument, my_bool set_maximum_value); static char *check_struct_option(char *cur_arg, char *key_name); @@ -101,10 +101,9 @@ static void default_reporter(enum loglevel level, one. Call function 'get_one_option()' once for each option. */ -static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *); +static my_getopt_value getopt_get_addr; -void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint, - const struct my_option *, int *)) +void my_getopt_register_get_addr(my_getopt_value func_addr) { getopt_get_addr= func_addr; } @@ -119,7 +118,7 @@ int handle_options(int *argc, char ***argv, char **pos, **pos_end, *optend, *UNINIT_VAR(prev_found), *opt_str, key_name[FN_REFLEN]; const struct my_option *optp; - uchar* *value; + void *value; int error, i; LINT_INIT(opt_found); @@ -173,7 +172,7 @@ int handle_options(int *argc, char ***argv, "%s: Option '--set-variable' is deprecated. " "Use --variable-name=value instead.", my_progname); - + must_be_var= 1; if (cur_arg[13] == '=') { @@ -378,7 +377,7 @@ int handle_options(int *argc, char ***argv, optp->value; if (error) return error; - + if (optp->arg_type == NO_ARG) { if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL) @@ -406,8 +405,8 @@ int handle_options(int *argc, char ***argv, else { my_getopt_error_reporter(WARNING_LEVEL, - "%s: ignoring option '--%s' due to \ -invalid value '%s'", + "%s: ignoring option '--%s' due to " + "invalid value '%s'", my_progname, optp->name, optend); continue; } @@ -611,15 +610,14 @@ static char *check_struct_option(char *cur_arg, char *key_name) Will set the option value to given value */ -static int setval(const struct my_option *opts, uchar* *value, char *argument, +static int setval(const struct my_option *opts, void *value, char *argument, my_bool set_maximum_value) { int err= 0; if (value && argument) { - uchar* *result_pos= ((set_maximum_value) ? - opts->u_max_value : value); + void *result_pos= ((set_maximum_value) ? opts->u_max_value : value); if (!result_pos) return EXIT_NO_PTR_TO_VARIABLE; @@ -994,7 +992,7 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err) value Pointer to variable */ -static void init_one_value(const struct my_option *option, uchar* *variable, +static void init_one_value(const struct my_option *option, void *variable, longlong value) { DBUG_ENTER("init_one_value"); @@ -1068,7 +1066,7 @@ static void init_one_value(const struct my_option *option, uchar* *variable, value Pointer to variable */ -static void fini_one_value(const struct my_option *option, uchar* *variable, +static void fini_one_value(const struct my_option *option, void *variable, longlong value __attribute__ ((unused))) { DBUG_ENTER("fini_one_value"); @@ -1109,7 +1107,7 @@ static void init_variables(const struct my_option *options, DBUG_ENTER("init_variables"); for (; options->name; options++) { - uchar* *variable; + void *variable; DBUG_PRINT("options", ("name: '%s'", options->name)); /* We must set u_max_value first as for some variables @@ -1224,7 +1222,7 @@ void my_print_variables(const struct my_option *options) printf("--------------------------------- -----------------------------\n"); for (optp= options; optp->id; optp++) { - uchar* *value= (optp->var_type & GET_ASK_ADDR ? + void *value= (optp->var_type & GET_ASK_ADDR ? (*getopt_get_addr)("", 0, optp, 0) : optp->value); if (value) { |