2011-06-30 17:37:13 +02:00
|
|
|
/*
|
2013-09-06 22:31:30 +02:00
|
|
|
Copyright (c) 2002, 2013, Oracle and/or its affiliates
|
2020-06-18 12:58:54 +02:00
|
|
|
Copyright (c) 2009, 2020, MariaDB
|
2002-01-25 22:34:37 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-01-25 22:34:37 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2020-01-29 13:50:26 +01:00
|
|
|
#include <mysys_priv.h>
|
2013-03-25 23:03:13 +01:00
|
|
|
#include <my_default.h>
|
2002-01-25 22:34:37 +01:00
|
|
|
#include <m_string.h>
|
|
|
|
#include <stdlib.h>
|
2002-05-29 14:07:30 +02:00
|
|
|
#include <mysys_err.h>
|
2004-08-19 20:26:00 +02:00
|
|
|
#include <my_getopt.h>
|
2007-10-04 10:34:00 +02:00
|
|
|
#include <errno.h>
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2019-09-29 14:48:11 +02:00
|
|
|
my_bool is_file_marker(const char* arg);
|
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.
2010-06-10 22:16:43 +02:00
|
|
|
typedef void (*init_func_p)(const struct my_option *option, void *variable,
|
2007-10-04 19:55:08 +02:00
|
|
|
longlong value);
|
|
|
|
|
2004-08-31 18:27:58 +02:00
|
|
|
static void default_reporter(enum loglevel level, const char *format, ...);
|
|
|
|
my_error_reporter my_getopt_error_reporter= &default_reporter;
|
|
|
|
|
2010-07-02 21:38:04 +02:00
|
|
|
static int findopt(char *, uint, const struct my_option **, const char **);
|
2019-09-29 14:38:53 +02:00
|
|
|
static my_bool getopt_compare_strings(const char *, const char *, uint);
|
2002-06-11 10:20:31 +02:00
|
|
|
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
|
2009-12-22 10:35:56 +01:00
|
|
|
static ulonglong getopt_ull(char *, const struct my_option *, int *);
|
2007-07-30 10:33:50 +02:00
|
|
|
static double getopt_double(char *arg, const struct my_option *optp, int *err);
|
2009-12-22 10:35:56 +01:00
|
|
|
static void init_variables(const struct my_option *, init_func_p);
|
2010-06-11 03:30:49 +02:00
|
|
|
static void fini_one_value(const struct my_option *, void *, longlong);
|
2021-11-22 12:29:15 +01:00
|
|
|
static int setval(const struct my_option *, void *, char *, my_bool, const char *);
|
2003-06-27 17:51:39 +02:00
|
|
|
static char *check_struct_option(char *cur_arg, char *key_name);
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-06-09 22:27:07 +02:00
|
|
|
/*
|
|
|
|
The following three variables belong to same group and the number and
|
|
|
|
order of their arguments must correspond to each other.
|
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
static const char *special_opt_prefix[]=
|
2015-08-10 21:45:11 +02:00
|
|
|
{"skip", "disable", "enable", "maximum", "loose", "autoset", 0};
|
2002-06-09 22:27:07 +02:00
|
|
|
static const uint special_opt_prefix_lengths[]=
|
2015-08-10 21:45:11 +02:00
|
|
|
{ 4, 7, 6, 7, 5, 7, 0};
|
2002-06-11 10:20:31 +02:00
|
|
|
enum enum_special_opt
|
2015-08-10 21:45:11 +02:00
|
|
|
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE, OPT_AUTOSET};
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-04-02 19:29:53 +02:00
|
|
|
char *disabled_my_option= (char*) "0";
|
2009-12-22 10:35:56 +01:00
|
|
|
char *enabled_my_option= (char*) "1";
|
2015-09-03 18:06:55 +02:00
|
|
|
char *autoset_my_option= (char*) "auto";
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2015-01-07 12:13:21 +01:00
|
|
|
/*
|
2002-06-09 22:27:07 +02:00
|
|
|
This is a flag that can be set in client programs. 0 means that
|
2002-05-29 14:07:30 +02:00
|
|
|
my_getopt will not print error messages, but the client should do
|
2002-06-09 22:27:07 +02:00
|
|
|
it by itself
|
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-05-29 14:07:30 +02:00
|
|
|
my_bool my_getopt_print_errors= 1;
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2015-01-07 12:13:21 +01:00
|
|
|
/*
|
2007-03-02 17:43:45 +01:00
|
|
|
This is a flag that can be set in client programs. 1 means that
|
|
|
|
my_getopt will skip over options it does not know how to handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool my_getopt_skip_unknown= 0;
|
|
|
|
|
2015-01-07 12:13:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
This is a flag that can be set in client programs. 1 means that
|
|
|
|
my_getopt will reconize command line options by their unambiguous
|
|
|
|
prefixes. 0 means an option must be always specified in full.
|
|
|
|
*/
|
|
|
|
my_bool my_getopt_prefix_matching= 1;
|
|
|
|
|
2020-06-08 10:45:56 +02:00
|
|
|
/*
|
|
|
|
This is a flag that can be set in client programs. 1 means that
|
|
|
|
handle_options() will not initialize options to default values.
|
|
|
|
*/
|
|
|
|
my_bool my_handle_options_init_variables = 1;
|
|
|
|
|
2019-09-29 14:38:53 +02:00
|
|
|
my_getopt_value my_getopt_get_addr= 0;
|
|
|
|
|
|
|
|
static void default_reporter(enum loglevel level, const char *format, ...)
|
mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE
gen_lex_hash.cc:
Added NULL error reporting parameter to handle_options
log.cc:
Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did.
mysqld.cc:
Added option_error_reporter callback function and pass that into handle_options
mysql.cc:
Added NULL as error reporter arg to the end of handle_options
Many files:
Added NULL error reporter parameter as the last paramter to handle_options
my_getopt.c:
Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error
my_getopt.h:
Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback
mysqld.dsp:
Added custom build step for compiling message file and added message resource file (output of mc)
VC++Files/sql/mysqld.dsp:
Added custom build step for compiling message file and added message resource file (output of mc)
client/mysqladmin.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlcheck.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqldump.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlimport.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlmanager-pwgen.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlmanagerc.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlbinlog.cc:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlshow.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqltest.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/my_print_defaults.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/mysql_install.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/mysql_waitpid.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/perror.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/resolve_stack_dump.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/resolveip.c:
Added NULL error reporter parameter as the last paramter to handle_options
isam/isamchk.c:
Added NULL error reporter parameter as the last paramter to handle_options
isam/pack_isam.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/mi_test1.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisam_ftdump.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisamchk.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisampack.c:
Added NULL error reporter parameter as the last paramter to handle_options
include/my_getopt.h:
Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback
mysys/my_getopt.c:
Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error
tools/mysqlmanager.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysql.cc:
Added NULL as error reporter arg to the end of handle_options
sql/mysqld.cc:
Added option_error_reporter callback function and pass that into handle_options
sql/log.cc:
Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did.
sql/gen_lex_hash.cc:
Added NULL error reporting parameter to handle_options
sql/mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
2004-08-14 03:38:37 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("default_reporter");
|
|
|
|
|
2004-08-26 15:19:46 +02:00
|
|
|
va_start(args, format);
|
2006-11-10 13:25:10 +01:00
|
|
|
if (level == WARNING_LEVEL)
|
|
|
|
fprintf(stderr, "%s", "Warning: ");
|
|
|
|
else if (level == INFORMATION_LEVEL)
|
|
|
|
fprintf(stderr, "%s", "Info: ");
|
2004-08-26 15:19:46 +02:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
fputc('\n', stderr);
|
2006-12-06 22:03:56 +01:00
|
|
|
fflush(stderr);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_VOID_RETURN;
|
mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE
gen_lex_hash.cc:
Added NULL error reporting parameter to handle_options
log.cc:
Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did.
mysqld.cc:
Added option_error_reporter callback function and pass that into handle_options
mysql.cc:
Added NULL as error reporter arg to the end of handle_options
Many files:
Added NULL error reporter parameter as the last paramter to handle_options
my_getopt.c:
Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error
my_getopt.h:
Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback
mysqld.dsp:
Added custom build step for compiling message file and added message resource file (output of mc)
VC++Files/sql/mysqld.dsp:
Added custom build step for compiling message file and added message resource file (output of mc)
client/mysqladmin.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlcheck.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqldump.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlimport.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlmanager-pwgen.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlmanagerc.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlbinlog.cc:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqlshow.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysqltest.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/my_print_defaults.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/mysql_install.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/mysql_waitpid.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/perror.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/resolve_stack_dump.c:
Added NULL error reporter parameter as the last paramter to handle_options
extra/resolveip.c:
Added NULL error reporter parameter as the last paramter to handle_options
isam/isamchk.c:
Added NULL error reporter parameter as the last paramter to handle_options
isam/pack_isam.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/mi_test1.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisam_ftdump.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisamchk.c:
Added NULL error reporter parameter as the last paramter to handle_options
myisam/myisampack.c:
Added NULL error reporter parameter as the last paramter to handle_options
include/my_getopt.h:
Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback
mysys/my_getopt.c:
Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error
tools/mysqlmanager.c:
Added NULL error reporter parameter as the last paramter to handle_options
client/mysql.cc:
Added NULL as error reporter arg to the end of handle_options
sql/mysqld.cc:
Added option_error_reporter callback function and pass that into handle_options
sql/log.cc:
Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did.
sql/gen_lex_hash.cc:
Added NULL error reporting parameter to handle_options
sql/mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
2004-08-14 03:38:37 +02:00
|
|
|
}
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2013-05-19 20:08:06 +02:00
|
|
|
union ull_dbl
|
|
|
|
{
|
|
|
|
ulonglong ull;
|
|
|
|
double dbl;
|
|
|
|
};
|
|
|
|
|
2023-04-26 13:27:01 +02:00
|
|
|
|
|
|
|
static inline int cmp_opt_name(const char *a, const char *b)
|
|
|
|
{
|
|
|
|
return my_strcasecmp_latin1(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-19 20:08:06 +02:00
|
|
|
/**
|
|
|
|
Returns an ulonglong value containing a raw
|
|
|
|
representation of the given double value.
|
|
|
|
*/
|
|
|
|
ulonglong getopt_double2ulonglong(double v)
|
|
|
|
{
|
|
|
|
union ull_dbl u;
|
|
|
|
u.dbl= v;
|
|
|
|
compile_time_assert(sizeof(ulonglong) >= sizeof(double));
|
|
|
|
return u.ull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the double value which corresponds to
|
|
|
|
the given raw representation.
|
|
|
|
*/
|
|
|
|
double getopt_ulonglong2double(ulonglong v)
|
|
|
|
{
|
|
|
|
union ull_dbl u;
|
|
|
|
u.ull= v;
|
|
|
|
return u.dbl;
|
|
|
|
}
|
|
|
|
|
2021-11-22 12:29:15 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
/**
|
|
|
|
|
|
|
|
On Windows, if program is running in UTF8 mode, but some arguments are not UTF8.
|
|
|
|
|
|
|
|
This will mostly likely be a sign of old "ANSI" my.ini, and it is likely that
|
|
|
|
something will go wrong, e.g file access error.
|
|
|
|
*/
|
|
|
|
static void validate_value(const char *key, const char *value,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
MY_STRCOPY_STATUS status;
|
|
|
|
const struct charset_info_st *cs= &my_charset_utf8mb4_bin;
|
|
|
|
size_t len;
|
|
|
|
if (GetACP() != CP_UTF8)
|
|
|
|
return;
|
|
|
|
if (!(len= strlen(value)))
|
|
|
|
return;
|
|
|
|
cs->cset->well_formed_char_length(cs, value, value + len, len, &status);
|
|
|
|
if (!status.m_well_formed_error_pos)
|
|
|
|
return;
|
|
|
|
if (filename && *filename)
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
|
|
|
"%s: invalid (non-UTF8) characters found for option '%s'"
|
|
|
|
" in file '%s'",
|
|
|
|
my_progname, key, filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(
|
|
|
|
WARNING_LEVEL, "%s: invalid (non-UTF8) characters for option %s",
|
|
|
|
my_progname, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define validate_value(key, value, filename) (void)filename
|
|
|
|
#endif
|
|
|
|
|
2024-02-25 03:03:44 +01:00
|
|
|
#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); (*argc)--; continue; }
|
2023-12-12 06:21:10 +01:00
|
|
|
|
2024-03-12 15:26:29 +01:00
|
|
|
void warn_deprecated(const struct my_option *optp)
|
|
|
|
{
|
|
|
|
char buf1[NAME_CHAR_LEN + 3];
|
|
|
|
strxmov(buf1, "--", optp->name, NullS);
|
|
|
|
convert_underscore_to_dash(buf1, strlen(buf1));
|
|
|
|
if (IS_DEPRECATED_NO_REPLACEMENT(optp->deprecation_substitute))
|
|
|
|
my_getopt_error_reporter(WARNING_LEVEL, "%s is deprecated and will be "
|
|
|
|
"removed in a future release", buf1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf2[NAME_CHAR_LEN + 3];
|
|
|
|
strxmov(buf2, "--", optp->deprecation_substitute, NullS);
|
|
|
|
convert_underscore_to_dash(buf2, strlen(buf2));
|
|
|
|
my_getopt_error_reporter(WARNING_LEVEL, "%s is deprecated and will be "
|
|
|
|
"removed in a future release. Please use %s instead.", buf1, buf2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 04:19:51 +01:00
|
|
|
/**
|
|
|
|
Handle command line options.
|
|
|
|
Sort options.
|
|
|
|
Put options first, until special end of options (--),
|
|
|
|
or until the end of argv. Parse options, check that the given option
|
|
|
|
matches with one of the options in struct 'my_option'.
|
|
|
|
Check that option was given an argument if it requires one
|
2019-09-29 20:30:28 +02:00
|
|
|
Call the 'get_one_option()' function once for each option.
|
2010-08-26 02:59:28 +02:00
|
|
|
|
|
|
|
Note that handle_options() can be invoked multiple times to
|
|
|
|
parse a command line in several steps.
|
|
|
|
In this case, use the global flag @c my_getopt_skip_unknown to indicate
|
|
|
|
that options unknown in the current step should be preserved in the
|
|
|
|
command line for later parsing in subsequent steps.
|
|
|
|
|
|
|
|
For 'long' options (--a_long_option), @c my_getopt_skip_unknown is
|
|
|
|
fully supported. Command line parameters such as:
|
|
|
|
- "--a_long_option"
|
|
|
|
- "--a_long_option=value"
|
|
|
|
- "--a_long_option value"
|
|
|
|
will be preserved as is when the option is not known.
|
|
|
|
|
|
|
|
For 'short' options (-S), support for @c my_getopt_skip_unknown
|
|
|
|
comes with some limitation, because several short options
|
|
|
|
can also be specified together in the same command line argument,
|
|
|
|
as in "-XYZ".
|
|
|
|
|
|
|
|
The first use case supported is: all short options are declared.
|
|
|
|
handle_options() will be able to interpret "-XYZ" as one of:
|
|
|
|
- an unknown X option
|
|
|
|
- "-X -Y -Z", three short options with no arguments
|
|
|
|
- "-X -YZ", where Y is a short option with argument Z
|
|
|
|
- "-XYZ", where X is a short option with argument YZ
|
|
|
|
based on the full short options specifications.
|
|
|
|
|
|
|
|
The second use case supported is: no short option is declared.
|
|
|
|
handle_options() will reject "-XYZ" as unknown, to be parsed later.
|
|
|
|
|
|
|
|
The use case that is explicitly not supported is to provide
|
|
|
|
only a partial list of short options to handle_options().
|
|
|
|
This function can not be expected to extract some option Y
|
|
|
|
in the middle of the string "-XYZ" in these conditions,
|
|
|
|
without knowing if X will be declared an option later.
|
|
|
|
|
|
|
|
Note that this limitation only impacts parsing of several
|
|
|
|
short options from the same command line argument,
|
|
|
|
as in "mysqld -anW5".
|
|
|
|
When each short option is properly separated out in the command line
|
|
|
|
argument, for example in "mysqld -a -n -w5", the code would actually
|
|
|
|
work even with partial options specs given at each stage.
|
|
|
|
|
2009-12-10 04:19:51 +01:00
|
|
|
@param [in, out] argc command line options (count)
|
|
|
|
@param [in, out] argv command line options (values)
|
|
|
|
@param [in] longopts descriptor of all valid options
|
2019-09-29 20:30:28 +02:00
|
|
|
@param [in] get_one_option callback function to process each option
|
2009-12-10 04:19:51 +01:00
|
|
|
@return error in case of ambiguous or unknown options,
|
|
|
|
0 on success.
|
|
|
|
*/
|
2019-09-29 20:30:28 +02:00
|
|
|
int handle_options(int *argc, char ***argv, const struct my_option *longopts,
|
2004-08-31 18:27:58 +02:00
|
|
|
my_get_one_option get_one_option)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2010-09-24 22:04:36 +02:00
|
|
|
uint UNINIT_VAR(opt_found), argvpos= 0, length;
|
2003-11-21 00:53:01 +01:00
|
|
|
my_bool end_of_options= 0, must_be_var, set_maximum_value,
|
2015-08-10 21:45:11 +02:00
|
|
|
option_is_loose, option_is_autoset;
|
Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.
One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.
There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
BUILD/SETUP.sh:
Remove flags that are implied by -Wall and -Wextra.
Do not warn about unused parameters in C++.
BUILD/check-cpu:
Print only the compiler version instead of verbose banner.
Although the option is gcc specific, the check was only
being used for GCC specific checks anyway.
client/mysql.cc:
bcmp is no longer defined.
client/mysqltest.cc:
Pass a string to function expecting a format string.
Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
Always define _GNU_SOURCE when compiling GNU readline.
Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
Condition for the code to be meaningful.
configure.in:
Remove check for bcmp.
extra/comp_err.c:
Use appropriate type.
extra/replace.c:
Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
Do not ignore the return value of fgets. Retrieve the file
position if fgets succeed -- if it fails, the function will
bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
Use a single array instead of accessing positions of the sbox_
through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
Do not define type within a anonymous union.
Use a variable to return a value instead of
leaving the result in a register -- compiler
does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
Define handler for pure virtual functions.
Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
Function must have C language linkage.
include/m_string.h:
Remove check which relied on bcmp being defined -- they weren't
being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
Remove bogus helpers which were used only in a few files and
were causing warnings about dead code.
include/my_global.h:
Due to G++ bug, always silence false-positive uninitialized
variables warnings when compiling C++ code with G++.
Remove bogus helper.
libmysql/Makefile.shared:
Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
Leave space of the ending nul.
mysys/mf_pack.c:
Replace bcmp with memcmp.
mysys/my_bitmap.c:
Dead code removal.
mysys/my_gethwaddr.c:
Remove unused variable.
mysys/my_getopt.c:
Silence bogus uninitialized variable warning.
Do not cast away the constant qualifier.
mysys/safemalloc.c:
Cast to expected type.
mysys/thr_lock.c:
Silence bogus uninitialized variable warning.
sql/field.cc:
Replace bogus helper with a more appropriate logic which is
used throughout the code.
sql/item.cc:
Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
Simplify code to avoid signedness related warnings.
sql/log_event.cc:
Replace use of bcmp with memcmp.
No need to use helpers for simple bit operations.
sql/log_event_old.cc:
Replace bmove_align with memcpy.
sql/mysqld.cc:
Move use declaration of variable to the ifdef block where it
is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
Cast to expected type and silence bogus warning.
sql/sql_class.h:
Don't use enum values as bit flags, the supposed type safety is
bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
Only declare variable when necessary.
sql/unireg.h:
Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
Silence bogus warning.
storage/myisam/mi_open.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
storage/myisam/mi_page.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
strings/bcmp.c:
Remove built-in bcmp.
strings/ctype-ucs2.c:
Silence bogus warning.
tests/mysql_client_test.c:
Use a appropriate type as expected by simple_command().
2010-07-02 20:30:47 +02:00
|
|
|
char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN];
|
2019-09-29 14:48:11 +02:00
|
|
|
char *filename= (char*)"";
|
2011-04-25 17:22:25 +02:00
|
|
|
const char *UNINIT_VAR(prev_found);
|
2002-01-25 22:34:37 +01:00
|
|
|
const struct my_option *optp;
|
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.
2010-06-10 22:16:43 +02:00
|
|
|
void *value;
|
2023-12-12 06:21:10 +01:00
|
|
|
int ho_error= 0, error, i;
|
2009-10-02 10:25:53 +02:00
|
|
|
my_bool is_cmdline_arg= 1;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("handle_options");
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2007-04-24 10:40:23 +02:00
|
|
|
/* handle_options() assumes arg0 (program name) always exists */
|
2019-10-28 15:21:42 +01:00
|
|
|
DBUG_ASSERT(*argc >= 1);
|
|
|
|
DBUG_ASSERT(*argv);
|
2002-01-30 04:08:17 +01:00
|
|
|
(*argc)--; /* Skip the program name */
|
|
|
|
(*argv)++; /* --- || ---- */
|
2020-06-08 10:45:56 +02:00
|
|
|
if (my_handle_options_init_variables)
|
2024-04-21 13:29:31 +02:00
|
|
|
init_variables(longopts, my_getopt_init_one_value);
|
2002-05-07 19:35:06 +02:00
|
|
|
|
2019-09-29 14:48:11 +02:00
|
|
|
is_cmdline_arg= !is_file_marker(**argv);
|
2009-10-02 10:25:53 +02:00
|
|
|
|
2023-12-12 06:21:10 +01:00
|
|
|
for (pos= *argv, pos_end=pos+ *argc; pos < pos_end ; pos++)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
char **first= pos;
|
2002-01-25 22:34:37 +01:00
|
|
|
char *cur_arg= *pos;
|
2010-09-02 03:13:24 +02:00
|
|
|
opt_found= 0;
|
2019-09-29 14:48:11 +02:00
|
|
|
if (!is_cmdline_arg)
|
2009-10-02 10:25:53 +02:00
|
|
|
{
|
2019-09-29 14:48:11 +02:00
|
|
|
if (is_file_marker(cur_arg))
|
|
|
|
{
|
|
|
|
pos++;
|
|
|
|
filename= *pos;
|
|
|
|
is_cmdline_arg= *filename == 0; /* empty file name = command line */
|
|
|
|
if (my_getopt_skip_unknown)
|
|
|
|
{
|
|
|
|
(*argv)[argvpos++]= cur_arg;
|
|
|
|
(*argv)[argvpos++]= filename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(*argc)-= 2;
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-02 10:25:53 +02:00
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-02-06 16:22:43 +01:00
|
|
|
char *argument= 0;
|
|
|
|
must_be_var= 0;
|
2002-01-30 04:08:17 +01:00
|
|
|
set_maximum_value= 0;
|
2002-05-11 13:36:34 +02:00
|
|
|
option_is_loose= 0;
|
2015-08-10 21:45:11 +02:00
|
|
|
option_is_autoset= 0;
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2002-02-06 16:22:43 +01:00
|
|
|
cur_arg++; /* skip '-' */
|
2010-03-03 20:22:02 +01:00
|
|
|
if (*cur_arg == '-') /* check for long option, */
|
|
|
|
{
|
|
|
|
if (!*++cur_arg) /* skip the double dash */
|
|
|
|
{
|
|
|
|
/* '--' means end of options, look no further */
|
|
|
|
end_of_options= 1;
|
|
|
|
(*argc)--;
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-27 17:51:39 +02:00
|
|
|
opt_str= check_struct_option(cur_arg, key_name);
|
|
|
|
optend= strcend(opt_str, '=');
|
2005-06-13 12:41:15 +02:00
|
|
|
length= (uint) (optend - opt_str);
|
2002-02-06 16:22:43 +01:00
|
|
|
if (*optend == '=')
|
|
|
|
optend++;
|
|
|
|
else
|
2003-06-27 17:51:39 +02:00
|
|
|
optend= 0;
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-01-25 22:34:37 +01:00
|
|
|
/*
|
|
|
|
Find first the right option. Return error in case of an ambiguous,
|
|
|
|
or unknown option
|
|
|
|
*/
|
2002-01-30 04:08:17 +01:00
|
|
|
optp= longopts;
|
2003-06-27 17:51:39 +02:00
|
|
|
if (!(opt_found= findopt(opt_str, length, &optp, &prev_found)))
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Didn't find any matching option. Let's see if someone called
|
|
|
|
option with a special option prefix
|
|
|
|
*/
|
2002-01-30 04:08:17 +01:00
|
|
|
if (!must_be_var)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-02-06 16:22:43 +01:00
|
|
|
if (optend)
|
2002-05-11 13:36:34 +02:00
|
|
|
must_be_var= 1; /* option is followed by an argument */
|
2002-01-30 04:08:17 +01:00
|
|
|
for (i= 0; special_opt_prefix[i]; i++)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2003-06-27 17:51:39 +02:00
|
|
|
if (!getopt_compare_strings(special_opt_prefix[i], opt_str,
|
2002-07-23 17:31:22 +02:00
|
|
|
special_opt_prefix_lengths[i]) &&
|
2005-04-18 23:22:57 +02:00
|
|
|
(opt_str[special_opt_prefix_lengths[i]] == '-' ||
|
|
|
|
opt_str[special_opt_prefix_lengths[i]] == '_'))
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-01-31 03:36:58 +01:00
|
|
|
/*
|
|
|
|
We were called with a special prefix, we can reuse opt_found
|
|
|
|
*/
|
2007-04-13 19:23:02 +02:00
|
|
|
opt_str+= special_opt_prefix_lengths[i] + 1;
|
|
|
|
length-= special_opt_prefix_lengths[i] + 1;
|
2002-06-09 22:27:07 +02:00
|
|
|
if (i == OPT_LOOSE)
|
2002-05-11 13:36:34 +02:00
|
|
|
option_is_loose= 1;
|
2015-08-10 21:45:11 +02:00
|
|
|
else if (i == OPT_AUTOSET)
|
|
|
|
option_is_autoset= 1;
|
2007-04-13 19:23:02 +02:00
|
|
|
if ((opt_found= findopt(opt_str, length, &optp, &prev_found)))
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
|
|
|
if (opt_found > 1)
|
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: ambiguous option '--%s-%s' (--%s-%s)",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, special_opt_prefix[i],
|
2009-12-22 10:35:56 +01:00
|
|
|
opt_str, special_opt_prefix[i],
|
2004-08-31 18:27:58 +02:00
|
|
|
prev_found);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_AMBIGUOUS_OPTION)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2002-06-09 22:27:07 +02:00
|
|
|
switch (i) {
|
|
|
|
case OPT_SKIP:
|
|
|
|
case OPT_DISABLE: /* fall through */
|
2002-08-28 12:14:11 +02:00
|
|
|
/*
|
|
|
|
double negation is actually enable again,
|
|
|
|
for example: --skip-option=0 -> option = TRUE
|
|
|
|
*/
|
|
|
|
optend= (optend && *optend == '0' && !(*(optend + 1))) ?
|
2009-12-22 10:35:56 +01:00
|
|
|
enabled_my_option : disabled_my_option;
|
2002-06-09 22:27:07 +02:00
|
|
|
break;
|
|
|
|
case OPT_ENABLE:
|
2002-08-28 12:14:11 +02:00
|
|
|
optend= (optend && *optend == '0' && !(*(optend + 1))) ?
|
2009-12-22 10:35:56 +01:00
|
|
|
disabled_my_option : enabled_my_option;
|
2002-06-09 22:27:07 +02:00
|
|
|
break;
|
|
|
|
case OPT_MAXIMUM:
|
2002-01-30 04:08:17 +01:00
|
|
|
set_maximum_value= 1;
|
|
|
|
must_be_var= 1;
|
2002-06-09 22:27:07 +02:00
|
|
|
break;
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
2002-01-31 03:36:58 +01:00
|
|
|
break; /* break from the inner loop, main loop continues */
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2007-04-13 19:23:02 +02:00
|
|
|
i= -1; /* restart the loop */
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!opt_found)
|
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
if (my_getopt_skip_unknown)
|
|
|
|
{
|
2010-03-03 20:22:02 +01:00
|
|
|
/* Preserve all the components of this unknown option. */
|
2007-03-02 17:43:45 +01:00
|
|
|
do {
|
|
|
|
(*argv)[argvpos++]= *first++;
|
|
|
|
} while (first <= pos);
|
|
|
|
continue;
|
|
|
|
}
|
2002-01-25 22:34:37 +01:00
|
|
|
if (must_be_var)
|
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(option_is_loose ?
|
|
|
|
WARNING_LEVEL : ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: unknown variable '%s'",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, cur_arg);
|
2002-05-11 13:36:34 +02:00
|
|
|
if (!option_is_loose)
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNKNOWN_VARIABLE)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(option_is_loose ?
|
|
|
|
WARNING_LEVEL : ERROR_LEVEL,
|
2007-12-01 15:53:56 +01:00
|
|
|
"%s: unknown option '--%s'",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, cur_arg);
|
2002-05-11 13:36:34 +02:00
|
|
|
if (!option_is_loose)
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNKNOWN_OPTION)
|
2002-05-11 13:36:34 +02:00
|
|
|
}
|
|
|
|
if (option_is_loose)
|
|
|
|
{
|
|
|
|
(*argc)--;
|
|
|
|
continue;
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (opt_found > 1)
|
|
|
|
{
|
|
|
|
if (must_be_var)
|
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: variable prefix '%s' is not unique",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, opt_str);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_VAR_PREFIX_NOT_UNIQUE)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: ambiguous option '--%s' (%s, %s)",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, opt_str, prev_found,
|
2004-08-31 18:27:58 +02:00
|
|
|
optp->name);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_AMBIGUOUS_OPTION)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
2004-01-14 03:58:37 +01:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
|
|
|
|
{
|
|
|
|
if (my_getopt_print_errors)
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: %s: Option '%s' used, but is disabled\n", my_progname,
|
|
|
|
option_is_loose ? "WARNING" : "ERROR", opt_str);
|
|
|
|
if (option_is_loose)
|
|
|
|
{
|
|
|
|
(*argc)--;
|
|
|
|
continue;
|
|
|
|
}
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_OPTION_DISABLED)
|
2004-01-14 03:58:37 +01:00
|
|
|
}
|
2008-10-27 10:57:59 +01:00
|
|
|
error= 0;
|
2019-09-29 14:38:53 +02:00
|
|
|
value= optp->var_type & GET_ASK_ADDR
|
|
|
|
? (*my_getopt_get_addr)(key_name, (uint)strlen(key_name), optp, &error)
|
|
|
|
: optp->value;
|
2008-10-27 10:57:59 +01:00
|
|
|
if (error)
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(error)
|
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.
2010-06-10 22:16:43 +02:00
|
|
|
|
2002-04-02 19:29:53 +02:00
|
|
|
if (optp->arg_type == NO_ARG)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2010-10-25 14:30:07 +02:00
|
|
|
/*
|
|
|
|
Due to historical reasons GET_BOOL var_types still accepts arguments
|
|
|
|
despite the NO_ARG arg_type attribute. This can seems a bit unintuitive
|
|
|
|
and care should be taken when refactoring this code.
|
|
|
|
*/
|
2003-06-27 17:51:39 +02:00
|
|
|
if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL)
|
2002-04-02 19:29:53 +02:00
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: option '--%s' cannot take an argument",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, optp->name);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_NO_ARGUMENT_ALLOWED)
|
2002-04-02 19:29:53 +02:00
|
|
|
}
|
2003-06-27 17:51:39 +02:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL)
|
2002-04-02 19:29:53 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Set bool to 1 if no argument or if the user has used
|
|
|
|
--enable-'option-name'.
|
|
|
|
*optend was set to '0' if one used --disable-option
|
2010-10-25 14:30:07 +02:00
|
|
|
*/
|
2004-02-03 19:10:45 +01:00
|
|
|
(*argc)--;
|
2005-09-06 19:19:49 +02:00
|
|
|
if (!optend || *optend == '1' ||
|
2023-04-26 13:27:01 +02:00
|
|
|
!cmp_opt_name(optend, "true") ||
|
|
|
|
!cmp_opt_name(optend, "on"))
|
2005-09-06 19:19:49 +02:00
|
|
|
*((my_bool*) value)= (my_bool) 1;
|
|
|
|
else if (*optend == '0' ||
|
2023-04-26 13:27:01 +02:00
|
|
|
!cmp_opt_name(optend, "false") ||
|
|
|
|
!cmp_opt_name(optend, "off"))
|
2005-09-06 19:19:49 +02:00
|
|
|
*((my_bool*) value)= (my_bool) 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
2009-12-22 10:35:56 +01:00
|
|
|
"%s: ignoring option '--%s' "
|
|
|
|
"due to invalid value '%s'",
|
2005-09-06 19:19:49 +02:00
|
|
|
my_progname, optp->name, optend);
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-29 16:30:57 +02:00
|
|
|
if (get_one_option(optp, *((my_bool*) value) ?
|
|
|
|
enabled_my_option : disabled_my_option,
|
|
|
|
filename))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_ARGUMENT_INVALID)
|
2024-03-12 15:26:29 +01:00
|
|
|
if (optp->deprecation_substitute)
|
|
|
|
warn_deprecated(optp);
|
2003-01-28 19:56:35 +01:00
|
|
|
continue;
|
2002-04-02 19:29:53 +02:00
|
|
|
}
|
|
|
|
argument= optend;
|
|
|
|
}
|
2015-08-10 21:45:11 +02:00
|
|
|
else if (option_is_autoset)
|
|
|
|
{
|
|
|
|
if (optend)
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
2015-09-03 18:06:55 +02:00
|
|
|
"%s: automatically set "
|
2015-08-10 21:45:11 +02:00
|
|
|
"option '--%s' cannot take an argument",
|
|
|
|
my_progname, optp->name);
|
|
|
|
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_NO_ARGUMENT_ALLOWED)
|
2015-08-10 21:45:11 +02:00
|
|
|
}
|
2019-09-29 20:30:28 +02:00
|
|
|
if (!(optp->var_type & GET_AUTO))
|
2015-08-10 21:45:11 +02:00
|
|
|
{
|
|
|
|
my_getopt_error_reporter(option_is_loose ?
|
|
|
|
WARNING_LEVEL : ERROR_LEVEL,
|
|
|
|
"%s: automatic setup request is "
|
|
|
|
"unsupported by option '--%s'",
|
|
|
|
my_progname, optp->name);
|
|
|
|
if (!option_is_loose)
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_ARGUMENT_INVALID)
|
2015-08-10 21:45:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
argument= autoset_my_option;
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
else if (optp->arg_type == REQUIRED_ARG && !optend)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2019-09-29 20:30:28 +02:00
|
|
|
/*
|
|
|
|
Check if there are more arguments after this one,
|
|
|
|
Note: options loaded from config file that requires value
|
|
|
|
should always be in the form '--option=value'.
|
|
|
|
*/
|
2009-10-02 10:25:53 +02:00
|
|
|
if (!is_cmdline_arg || !*++pos)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-05-29 14:07:30 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: option '--%s' requires an argument",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, optp->name);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_ARGUMENT_REQUIRED)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2002-01-30 04:08:17 +01:00
|
|
|
argument= *pos;
|
2002-01-25 22:34:37 +01:00
|
|
|
(*argc)--;
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
else
|
|
|
|
argument= optend;
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2002-01-31 03:36:58 +01:00
|
|
|
else /* must be short option */
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-05-31 15:23:36 +02:00
|
|
|
for (optend= cur_arg; *optend; optend++)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-05-31 15:23:36 +02:00
|
|
|
opt_found= 0;
|
2009-12-22 10:35:56 +01:00
|
|
|
for (optp= longopts; optp->name; optp++)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (optp->id && optp->id == (int) (uchar) *optend)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
|
|
|
/* Option recognized. Find next what to do with it */
|
2002-02-06 16:22:43 +01:00
|
|
|
opt_found= 1;
|
2004-01-14 03:58:37 +01:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
|
|
|
|
{
|
|
|
|
if (my_getopt_print_errors)
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: ERROR: Option '-%c' used, but is disabled\n",
|
|
|
|
my_progname, optp->id);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_OPTION_DISABLED)
|
2004-01-14 03:58:37 +01:00
|
|
|
}
|
2003-06-27 17:51:39 +02:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL &&
|
|
|
|
optp->arg_type == NO_ARG)
|
2002-04-03 14:44:20 +02:00
|
|
|
{
|
|
|
|
*((my_bool*) optp->value)= (my_bool) 1;
|
2019-09-29 16:30:57 +02:00
|
|
|
if (get_one_option(optp, argument, filename))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNSPECIFIED_ERROR)
|
2024-03-12 15:26:29 +01:00
|
|
|
if (optp->deprecation_substitute)
|
|
|
|
warn_deprecated(optp);
|
2003-01-28 19:56:35 +01:00
|
|
|
continue;
|
2002-04-03 14:44:20 +02:00
|
|
|
}
|
|
|
|
else if (optp->arg_type == REQUIRED_ARG ||
|
|
|
|
optp->arg_type == OPT_ARG)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
|
|
|
if (*(optend + 1))
|
|
|
|
{
|
2002-07-03 18:45:38 +02:00
|
|
|
/* The rest of the option is option argument */
|
2002-02-06 16:22:43 +01:00
|
|
|
argument= optend + 1;
|
2002-07-03 18:45:38 +02:00
|
|
|
/* This is in effect a jump out of the outer loop */
|
2002-02-06 16:22:43 +01:00
|
|
|
optend= (char*) " ";
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2004-04-28 15:33:03 +02:00
|
|
|
else
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2004-04-30 23:12:37 +02:00
|
|
|
if (optp->arg_type == OPT_ARG)
|
|
|
|
{
|
|
|
|
if (optp->var_type == GET_BOOL)
|
|
|
|
*((my_bool*) optp->value)= (my_bool) 1;
|
2019-09-29 16:30:57 +02:00
|
|
|
if (get_one_option(optp, argument, filename))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNSPECIFIED_ERROR)
|
2024-03-12 15:26:29 +01:00
|
|
|
if (optp->deprecation_substitute)
|
|
|
|
warn_deprecated(optp);
|
2004-04-30 23:12:37 +02:00
|
|
|
continue;
|
|
|
|
}
|
2002-01-25 22:34:37 +01:00
|
|
|
/* Check if there are more arguments after this one */
|
2004-04-28 15:33:03 +02:00
|
|
|
if (!pos[1])
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2004-04-28 15:33:03 +02:00
|
|
|
if (my_getopt_print_errors)
|
2004-08-31 18:27:58 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
"%s: option '-%c' requires an argument",
|
2004-09-01 03:12:09 +02:00
|
|
|
my_progname, optp->id);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_ARGUMENT_REQUIRED)
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2004-04-28 15:33:03 +02:00
|
|
|
argument= *++pos;
|
2002-01-25 22:34:37 +01:00
|
|
|
(*argc)--;
|
2002-02-06 16:22:43 +01:00
|
|
|
/* the other loop will break, because *optend + 1 == 0 */
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
2003-07-06 18:09:57 +02:00
|
|
|
if ((error= setval(optp, optp->value, argument,
|
2024-03-28 08:16:57 +01:00
|
|
|
set_maximum_value,filename)))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(error)
|
2019-09-29 16:30:57 +02:00
|
|
|
if (get_one_option(optp, argument, filename))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNSPECIFIED_ERROR)
|
2024-03-12 15:26:29 +01:00
|
|
|
if (optp->deprecation_substitute)
|
|
|
|
warn_deprecated(optp);
|
2002-01-25 22:34:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
if (!opt_found)
|
|
|
|
{
|
2010-08-26 02:59:28 +02:00
|
|
|
if (my_getopt_skip_unknown)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We are currently parsing a single argv[] argument
|
2010-08-26 16:34:18 +02:00
|
|
|
of the form "-XYZ".
|
|
|
|
One or the argument found (say Y) is not an option.
|
|
|
|
Hack the string "-XYZ" to make a "-YZ" substring in it,
|
|
|
|
and push that to the output as an unrecognized parameter.
|
2010-08-26 02:59:28 +02:00
|
|
|
*/
|
2010-08-26 16:34:18 +02:00
|
|
|
DBUG_ASSERT(optend > *pos);
|
|
|
|
DBUG_ASSERT(optend >= cur_arg);
|
|
|
|
DBUG_ASSERT(optend <= *pos + strlen(*pos));
|
|
|
|
DBUG_ASSERT(*optend);
|
|
|
|
optend--;
|
|
|
|
optend[0]= '-'; /* replace 'X' or '-' by '-' */
|
|
|
|
(*argv)[argvpos++]= optend;
|
2010-08-26 02:59:28 +02:00
|
|
|
/*
|
|
|
|
Do not continue to parse at the current "-XYZ" argument,
|
|
|
|
skip to the next argv[] argument instead.
|
|
|
|
*/
|
|
|
|
optend= (char*) " ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (my_getopt_print_errors)
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"%s: unknown option '-%c'",
|
|
|
|
my_progname, *optend);
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNKNOWN_OPTION)
|
2010-08-26 02:59:28 +02:00
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2010-08-26 02:59:28 +02:00
|
|
|
if (opt_found)
|
|
|
|
(*argc)--; /* option handled (short), decrease argument count */
|
2002-02-06 16:22:43 +01:00
|
|
|
continue;
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2015-08-10 21:45:11 +02:00
|
|
|
if ((!option_is_autoset) &&
|
2021-11-22 12:29:15 +01:00
|
|
|
((error= setval(optp, value, argument, set_maximum_value,filename))) &&
|
2011-04-25 17:22:25 +02:00
|
|
|
!option_is_loose)
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(error)
|
2019-09-29 16:30:57 +02:00
|
|
|
if (get_one_option(optp, argument, filename))
|
2023-12-12 06:21:10 +01:00
|
|
|
SET_HO_ERROR_AND_CONTINUE(EXIT_UNSPECIFIED_ERROR)
|
2024-03-12 15:26:29 +01:00
|
|
|
if (optp->deprecation_substitute)
|
|
|
|
warn_deprecated(optp);
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2010-08-26 02:59:28 +02:00
|
|
|
(*argc)--; /* option handled (long), decrease argument count */
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2002-01-31 03:36:58 +01:00
|
|
|
else /* non-option found */
|
2002-01-30 04:08:17 +01:00
|
|
|
(*argv)[argvpos++]= cur_arg;
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2023-12-12 06:21:10 +01:00
|
|
|
if (ho_error)
|
|
|
|
DBUG_RETURN(ho_error);
|
2002-06-11 10:20:31 +02:00
|
|
|
/*
|
|
|
|
Destroy the first, already handled option, so that programs that look
|
|
|
|
for arguments in 'argv', without checking 'argc', know when to stop.
|
|
|
|
Items in argv, before the destroyed one, are all non-option -arguments
|
|
|
|
to the program, yet to be (possibly) handled.
|
|
|
|
*/
|
|
|
|
(*argv)[argvpos]= 0;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
|
2003-06-27 17:51:39 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
function: check_struct_option
|
|
|
|
|
|
|
|
Arguments: Current argument under processing from argv and a variable
|
|
|
|
where to store the possible key name.
|
|
|
|
|
|
|
|
Return value: In case option is a struct option, returns a pointer to
|
|
|
|
the current argument at the position where the struct option (key_name)
|
|
|
|
ends, the next character after the dot. In case argument is not a struct
|
|
|
|
option, returns a pointer to the argument.
|
|
|
|
|
|
|
|
key_name will hold the name of the key, or 0 if not found.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *check_struct_option(char *cur_arg, char *key_name)
|
|
|
|
{
|
2003-06-30 14:49:29 +02:00
|
|
|
char *ptr, *end;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("check_struct_option");
|
2003-06-27 17:51:39 +02:00
|
|
|
|
2003-09-24 08:35:02 +02:00
|
|
|
ptr= strcend(cur_arg + 1, '.'); /* Skip the first character */
|
2003-06-30 14:49:29 +02:00
|
|
|
end= strcend(cur_arg, '=');
|
2003-06-27 17:51:39 +02:00
|
|
|
|
|
|
|
/*
|
2003-06-30 14:49:29 +02:00
|
|
|
If the first dot is after an equal sign, then it is part
|
2003-06-27 17:51:39 +02:00
|
|
|
of a variable value and the option is not a struct option.
|
2003-06-30 14:49:29 +02:00
|
|
|
Also, if the last character in the string before the ending
|
|
|
|
NULL, or the character right before equal sign is the first
|
|
|
|
dot found, the option is not a struct option.
|
2003-06-27 17:51:39 +02:00
|
|
|
*/
|
2003-06-30 14:49:29 +02:00
|
|
|
if (end - ptr > 1)
|
2003-06-27 17:51:39 +02:00
|
|
|
{
|
2005-06-13 12:41:15 +02:00
|
|
|
uint len= (uint) (ptr - cur_arg);
|
2003-07-06 18:09:57 +02:00
|
|
|
set_if_smaller(len, FN_REFLEN-1);
|
|
|
|
strmake(key_name, cur_arg, len);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(++ptr);
|
2003-06-27 17:51:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-06 18:09:57 +02:00
|
|
|
key_name[0]= 0;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(cur_arg);
|
2003-06-27 17:51:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:18:20 +01:00
|
|
|
/**
|
|
|
|
Parse a boolean command line argument
|
|
|
|
|
|
|
|
"ON", "TRUE" and "1" will return true,
|
|
|
|
other values will return false.
|
|
|
|
|
|
|
|
@param[in] argument The value argument
|
|
|
|
@return boolean value
|
|
|
|
*/
|
2011-01-14 23:18:22 +01:00
|
|
|
static my_bool get_bool_argument(const struct my_option *opts,
|
|
|
|
const char *argument)
|
2011-01-10 15:18:20 +01:00
|
|
|
{
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("get_bool_argument");
|
|
|
|
|
2023-04-26 13:27:01 +02:00
|
|
|
if (!cmp_opt_name(argument, "true") ||
|
|
|
|
!cmp_opt_name(argument, "on") ||
|
|
|
|
!cmp_opt_name(argument, "1"))
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(1);
|
2023-04-26 13:27:01 +02:00
|
|
|
else if (!cmp_opt_name(argument, "false") ||
|
|
|
|
!cmp_opt_name(argument, "off") ||
|
|
|
|
!cmp_opt_name(argument, "0"))
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2011-01-14 23:18:22 +01:00
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
|
|
|
"option '%s': boolean value '%s' wasn't recognized. Set to OFF.",
|
|
|
|
opts->name, argument);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2011-01-10 15:18:20 +01:00
|
|
|
}
|
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
/*
|
|
|
|
function: setval
|
|
|
|
|
|
|
|
Arguments: opts, argument
|
|
|
|
Will set the option value to given value
|
|
|
|
*/
|
|
|
|
|
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.
2010-06-10 22:16:43 +02:00
|
|
|
static int setval(const struct my_option *opts, void *value, char *argument,
|
2021-11-22 12:29:15 +01:00
|
|
|
my_bool set_maximum_value, const char *option_file)
|
2002-05-07 19:35:06 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
int err= 0, res= 0;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("setval");
|
2002-05-07 19:35:06 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!argument)
|
|
|
|
argument= enabled_my_option;
|
2002-05-07 19:35:06 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
if (set_maximum_value && !(value= opts->u_max_value))
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"%s: Maximum value of '%s' cannot be set",
|
|
|
|
my_progname, opts->name);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(EXIT_NO_PTR_TO_VARIABLE);
|
2009-12-22 10:35:56 +01:00
|
|
|
}
|
2002-05-07 19:35:06 +02:00
|
|
|
|
2003-06-27 17:51:39 +02:00
|
|
|
switch ((opts->var_type & GET_TYPE_MASK)) {
|
2004-04-28 15:33:03 +02:00
|
|
|
case GET_BOOL: /* If argument differs from 0, enable option, else disable */
|
2011-01-14 23:18:22 +01:00
|
|
|
*((my_bool*) value)= get_bool_argument(opts, argument);
|
2004-04-28 15:33:03 +02:00
|
|
|
break;
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_INT:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((int*) value)= (int) getopt_ll(argument, opts, &err);
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
case GET_UINT:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((uint*) value)= (uint) getopt_ull(argument, opts, &err);
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
break;
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_LONG:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((long*) value)= (long) getopt_ll(argument, opts, &err);
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
case GET_ULONG:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((long*) value)= (long) getopt_ull(argument, opts, &err);
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
break;
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_LL:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((longlong*) value)= getopt_ll(argument, opts, &err);
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_ULL:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((ulonglong*) value)= getopt_ull(argument, opts, &err);
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
2007-07-30 10:33:50 +02:00
|
|
|
case GET_DOUBLE:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((double*) value)= getopt_double(argument, opts, &err);
|
2007-07-30 10:33:50 +02:00
|
|
|
break;
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_STR:
|
2012-09-18 14:14:19 +02:00
|
|
|
/* If no argument or --enable-string-option, set string to "" */
|
|
|
|
*((char**) value)= argument == enabled_my_option ? (char*) "" : argument;
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_STR_ALLOC:
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
client/mysqldump.c:
Pass my_free directly as its signature is compatible with the
callback type -- which wasn't the case for free_table_ent.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(*((char**) value));
|
2020-01-29 13:50:26 +01:00
|
|
|
if (!(*((char**) value)= my_strdup(key_memory_defaults,
|
|
|
|
argument == enabled_my_option ? "" :
|
2012-09-18 14:14:19 +02:00
|
|
|
argument, MYF(MY_WME))))
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
res= EXIT_OUT_OF_MEMORY;
|
|
|
|
goto ret;
|
|
|
|
};
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
2007-03-02 17:43:45 +01:00
|
|
|
case GET_ENUM:
|
2009-06-25 15:55:26 +02:00
|
|
|
{
|
Fix for BUG#59894
"set optimizer_switch to e or d causes invalid memory writes/valgrind warnings":
due to prefix support, the argument "e" was overwritten with its full value
"engine_condition_pushdown", which caused a buffer overrun.
This was wrong usage of find_type(); other wrong usages are fixed here too.
Please start reading with the comment of typelib.c.
client/mysqldump.c:
A bug: find_type() expects a bitmap as 3rd argument
(each bit is a flag controlling a behaviour of the function);
here it was instead passed the length of the string to search!
That could give random behaviour of find_type()
depending on the string.
We rather need to pass a correct flag to find_type().
The correct flag is FIND_TYPE_BASIC (0).
Flag 8 is not needed as buff cannot have a comma (see how buff is filled).
Flag 1 looks like a superfluous restriction.
Flag 4 is not user-friendly (why use
--compatible=2 rather than --compatible=mysql40 ?, and
we probably not commit to "2" always meaning "mysql40"
until the end of times).
include/mysql.h.pp:
This isn't a problematic API change as we go from char* to const char*:
existing code will run unchanged.
include/typelib.h:
named constants. Not an enum to not significantly change
the declaration of find_type() which would be an API change
(typelib.h is included in mysql.h).
mysql-test/r/mysqldump.result:
correct result (see the two requested modes in SQL_MODE)
mysql-test/suite/sys_vars/t/optimizer_switch_basic.test:
test for BUG#59894. The second SET used to crash.
mysql-test/t/mysqldump.test:
we had no test for multiple modes in --compatible, which is
supported according to --help
mysys/typelib.c:
Fix for BUG#59894. parse_name() is asked to match "e" with a row
of the TYPELIB (the TYPELIB lists permitted flags of optimizer_switch;
and comes from optimizer_switch_names[] of sys_vars.cc).
find_type() is capable of supporting prefixes, but if it is not
passed flag 2 in third argument, it will overwrite its first
argument (the string to search for) with the complete name,
here overwriting "e" with "engine_condition_pushdown". But
as this "e" was a buffer allocated in an Item, it was not big
enough to host the longer name, thus the crash.
We don't need to know the complete flag's name; the output used
from find_type() is just the flag's number (== function's return
code). So we can pass flag 2 to find_type() in parse_name().
After doing this fix and the other fixes in this patch, all usages
of find_type() were using flag 2; in most usages the string to search for,
is not guaranteed to be long enough to host the complete name
(it is either directly from argv, or from alloc_root/my_malloc
done in an earlier call).
Thus, flag 2 is here made implicit: callers need not pass it anymore,
it is always automatically turned on.
This allows to eliminate an oddity: parse_name() took a const char**,
and then removed "const" before calling find_type(), which could
theoretically modify the pointed data, thus lying on constness.
Last, constants for find_type() are now named.
sql-common/client.c:
Two bugs:
1) The enum was not in sync with the array (due to a bad porting of WL 1054;
the extra OPT_ values are about options present in 5.1 and deleted in 5.5);
added a compile_time_assert() to make sure this doesn't happen again
2) find_type() was writing past the end of opt_arg; as opt_arg was allocated
with alloc_root() with no extra space, this was an overrun; it could be seen
when
** building with -DWITH_VALGRIND -DHAVE_purify -DEXTRA_DEBUG
** making execution go through the faulty code; this faulty
code is executed only if the client asks to read a configuration
file like this:
mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "/tmp/cnf.cnf");
so by adding such line to the start of mysql_client_test.c::client_connect(),
we could see the valgrind warning:
==30548== Invalid write of size 1
==30548== at 0x4C2624C: strcpy (mc_replace_strmem.c:303)
==30548== by 0x48DC29: find_type (typelib.c:120)
==30548== by 0x465686: mysql_read_default_options (client.c:1344)
==30548== by 0x46830F: mysql_real_connect (client.c:2971)
==30548== by 0x409339: client_connect (mysql_client_test.c:331)
==30548== by 0x463A7F: main (mysql_client_test.c:19902)
==30548== Address 0x61875ad is 0 bytes after a block of size 29 alloc'd
==30548== at 0x4C25153: malloc (vg_replace_malloc.c:195)
==30548== by 0x49BFF1: my_malloc (my_malloc.c:38)
==30548== by 0x49C65C: alloc_root (my_alloc.c:166)
==30548== by 0x48EF97: handle_default_option (default.c:381)
==30548== by 0x49068C: search_default_file_with_ext (default.c:992)
==30548== by 0x48F929: search_default_file (default.c:670)
==30548== by 0x48EDC4: my_search_option_files (default.c:312)
==30548== by 0x48F4B1: my_load_defaults (default.c:576)
==30548== by 0x46517A: mysql_read_default_options (client.c:1207)
==30548== by 0x46830F: mysql_real_connect (client.c:2971)
==30548== by 0x409339: client_connect (mysql_client_test.c:331)
==30548== by 0x463A7F: main (mysql_client_test.c:19902)
This is fixed by having find_type() not overwrite anymore.
sql/sql_help.cc:
cast not needed anymore.
sql/table.cc:
cast not needed anymore.
2011-02-11 15:00:09 +01:00
|
|
|
int type= find_type(argument, opts->typelib, FIND_TYPE_BASIC);
|
2010-08-03 18:21:13 +02:00
|
|
|
if (type == 0)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2010-08-03 18:01:30 +02:00
|
|
|
/*
|
|
|
|
Accept an integer representation of the enumerated item.
|
|
|
|
*/
|
|
|
|
char *endptr;
|
2010-08-04 14:58:09 +02:00
|
|
|
ulong arg= strtoul(argument, &endptr, 10);
|
2010-08-03 18:01:30 +02:00
|
|
|
if (*endptr || arg >= opts->typelib->count)
|
2010-08-03 18:21:13 +02:00
|
|
|
{
|
|
|
|
res= EXIT_ARGUMENT_INVALID;
|
|
|
|
goto ret;
|
|
|
|
}
|
2010-08-05 14:34:19 +02:00
|
|
|
*(ulong*)value= arg;
|
2010-08-03 18:01:30 +02:00
|
|
|
}
|
2012-08-17 17:02:44 +02:00
|
|
|
else if (type < 0)
|
|
|
|
{
|
|
|
|
res= EXIT_AMBIGUOUS_OPTION;
|
|
|
|
goto ret;
|
|
|
|
}
|
2010-08-03 18:01:30 +02:00
|
|
|
else
|
2010-08-05 14:34:19 +02:00
|
|
|
*(ulong*)value= type - 1;
|
2009-06-25 15:55:26 +02:00
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case GET_SET:
|
2009-12-22 10:35:56 +01:00
|
|
|
*((ulonglong*)value)= find_typeset(argument, opts->typelib, &err);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (err)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2023-09-20 14:46:55 +02:00
|
|
|
/* Check if option 'all' is used (to set all bits) */
|
2023-04-26 13:27:01 +02:00
|
|
|
if (!cmp_opt_name(argument, "all"))
|
2023-09-20 14:46:55 +02:00
|
|
|
*(ulonglong*) value= ((1ULL << opts->typelib->count) - 1);
|
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2023-09-20 14:46:55 +02:00
|
|
|
/* Accept an integer representation of the set */
|
|
|
|
char *endptr;
|
|
|
|
ulonglong arg= (ulonglong) strtol(argument, &endptr, 10);
|
|
|
|
if (*endptr || (arg >> 1) >= (1ULL << (opts->typelib->count-1)))
|
|
|
|
{
|
|
|
|
res= EXIT_ARGUMENT_INVALID;
|
|
|
|
goto ret;
|
|
|
|
};
|
|
|
|
*(ulonglong*)value= arg;
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
err= 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GET_FLAGSET:
|
|
|
|
{
|
|
|
|
char *error;
|
|
|
|
uint error_len;
|
|
|
|
|
|
|
|
*((ulonglong*)value)=
|
|
|
|
find_set_from_flags(opts->typelib, opts->typelib->count,
|
|
|
|
*(ulonglong *)value, opts->def_value,
|
2018-02-06 13:55:58 +01:00
|
|
|
argument, (uint)strlen(argument),
|
2009-12-22 10:35:56 +01:00
|
|
|
&error, &error_len);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
res= EXIT_ARGUMENT_INVALID;
|
|
|
|
goto ret;
|
|
|
|
};
|
|
|
|
}
|
2017-11-10 08:18:53 +01:00
|
|
|
break;
|
2017-07-21 18:56:41 +02:00
|
|
|
case GET_BIT:
|
|
|
|
{
|
|
|
|
uint tmp;
|
|
|
|
ulonglong bit= (opts->block_size >= 0 ?
|
|
|
|
opts->block_size :
|
|
|
|
-opts->block_size);
|
|
|
|
/*
|
|
|
|
This sets a bit stored in a longlong.
|
|
|
|
The bit to set is stored in block_size. If block_size is positive
|
|
|
|
then setting the bit means value is true. If block_size is negatitive,
|
|
|
|
then setting the bit means value is false.
|
|
|
|
*/
|
|
|
|
tmp= get_bool_argument(opts, argument);
|
|
|
|
if (opts->block_size < 0)
|
|
|
|
tmp= !tmp;
|
|
|
|
if (tmp)
|
|
|
|
(*(ulonglong*)value)|= bit;
|
|
|
|
else
|
|
|
|
(*(ulonglong*)value)&= ~bit;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
2017-07-21 18:56:41 +02:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
case GET_NO_ARG: /* get_one_option has taken care of the value already */
|
|
|
|
default: /* dummy default to avoid compiler warnings */
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
2002-05-14 20:41:55 +02:00
|
|
|
}
|
2002-05-07 19:35:06 +02:00
|
|
|
if (err)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2024-03-09 00:53:24 +01:00
|
|
|
res= err;
|
2009-12-22 10:35:56 +01:00
|
|
|
goto ret;
|
|
|
|
};
|
2002-05-07 19:35:06 +02:00
|
|
|
}
|
Changing all cost calculation to be given in milliseconds
This makes it easier to compare different costs and also allows
the optimizer to optimizer different storage engines more reliably.
- Added tests/check_costs.pl, a tool to verify optimizer cost calculations.
- Most engine costs has been found with this program. All steps to
calculate the new costs are documented in Docs/optimizer_costs.txt
- User optimizer_cost variables are given in microseconds (as individual
costs can be very small). Internally they are stored in ms.
- Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost
(9 ms) to common SSD cost (400MB/sec).
- Removed cost calculations for hard disks (rotation etc).
- Changed the following handler functions to return IO_AND_CPU_COST.
This makes it easy to apply different cost modifiers in ha_..time()
functions for io and cpu costs.
- scan_time()
- rnd_pos_time() & rnd_pos_call_time()
- keyread_time()
- Enhanched keyread_time() to calculate the full cost of reading of a set
of keys with a given number of ranges and optional number of blocks that
need to be accessed.
- Removed read_time() as keyread_time() + rnd_pos_time() can do the same
thing and more.
- Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks.
Used heap table costs for json_table. The rest are using default engine
costs.
- Added the following new optimizer variables:
- optimizer_disk_read_ratio
- optimizer_disk_read_cost
- optimizer_key_lookup_cost
- optimizer_row_lookup_cost
- optimizer_row_next_find_cost
- optimizer_scan_cost
- Moved all engine specific cost to OPTIMIZER_COSTS structure.
- Changed costs to use 'records_out' instead of 'records_read' when
recalculating costs.
- Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h.
This allows one to change costs without having to compile a lot of
files.
- Updated costs for filter lookup.
- Use a better cost estimate in best_extension_by_limited_search()
for the sorting cost.
- Fixed previous issues with 'filtered' explain column as we are now
using 'records_out' (min rows seen for table) to calculate filtering.
This greatly simplifies the filtering code in
JOIN_TAB::save_explain_data().
This change caused a lot of queries to be optimized differently than
before, which exposed different issues in the optimizer that needs to
be fixed. These fixes are in the following commits. To not have to
change the same test case over and over again, the changes in the test
cases are done in a single commit after all the critical change sets
are done.
InnoDB changes:
- Updated InnoDB to not divide big range cost with 2.
- Added cost for InnoDB (innobase_update_optimizer_costs()).
- Don't mark clustered primary key with HA_KEYREAD_ONLY. This will
prevent that the optimizer is trying to use index-only scans on
the clustered key.
- Disabled ha_innobase::scan_time() and ha_innobase::read_time() and
ha_innobase::rnd_pos_time() as the default engine cost functions now
works good for InnoDB.
Other things:
- Added --show-query-costs (\Q) option to mysql.cc to show the query
cost after each query (good when working with query costs).
- Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust
the value that user is given. This is used to change cost from
microseconds (user input) to milliseconds (what the server is
internally using).
- Added include/my_tracker.h ; Useful include file to quickly test
costs of a function.
- Use handler::set_table() in all places instead of 'table= arg'.
- Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and
shown in microseconds for the user but stored as milliseconds.
This is to make the numbers easier to read for the user (less
pre-zeros). Implemented in 'Sys_var_optimizer_cost' class.
- In test_quick_select() do not use index scans if 'no_keyread' is set
for the table. This is what we do in other places of the server.
- Added THD parameter to Unique::get_use_cost() and
check_index_intersect_extension() and similar functions to be able
to provide costs to called functions.
- Changed 'records' to 'rows' in optimizer_trace.
- Write more information to optimizer_trace.
- Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3)
to calculate usage space of keys in b-trees. (Before we used numeric
constants).
- Removed code that assumed that b-trees has similar costs as binary
trees. Replaced with engine calls that returns the cost.
- Added Bitmap::find_first_bit()
- Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia).
- Added records_init and records_after_filter to POSITION to remember
more of what best_access_patch() calculates.
- table_after_join_selectivity() changed to recalculate 'records_out'
based on the new fields from best_access_patch()
Bug fixes:
- Some queries did not update last_query_cost (was 0). Fixed by moving
setting thd->...last_query_cost in JOIN::optimize().
- Write '0' as number of rows for const tables with a matching row.
Some internals:
- Engine cost are stored in OPTIMIZER_COSTS structure. When a
handlerton is created, we also created a new cost variable for the
handlerton. We also create a new variable if the user changes a
optimizer cost for a not yet loaded handlerton either with command
line arguments or with SET
@@global.engine.optimizer_cost_variable=xx.
- There are 3 global OPTIMIZER_COSTS variables:
default_optimizer_costs The default costs + changes from the
command line without an engine specifier.
heap_optimizer_costs Heap table costs, used for temporary tables
tmp_table_optimizer_costs The cost for the default on disk internal
temporary table (MyISAM or Aria)
- The engine cost for a table is stored in table_share. To speed up
accesses the handler has a pointer to this. The cost is copied
to the table on first access. If one wants to change the cost one
must first update the global engine cost and then do a FLUSH TABLES.
This was done to be able to access the costs for an open table
without any locks.
- When a handlerton is created, the cost are updated the following way:
See sql/keycaches.cc for details:
- Use 'default_optimizer_costs' as a base
- Call hton->update_optimizer_costs() to override with the engines
default costs.
- Override the costs that the user has specified for the engine.
- One handler open, copy the engine cost from handlerton to TABLE_SHARE.
- Call handler::update_optimizer_costs() to allow the engine to update
cost for this particular table.
- There are two costs stored in THD. These are copied to the handler
when the table is used in a query:
- optimizer_where_cost
- optimizer_scan_setup_cost
- Simply code in best_access_path() by storing all cost result in a
structure. (Idea/Suggestion by Igor)
2022-08-11 12:05:23 +02:00
|
|
|
|
2021-11-22 12:29:15 +01:00
|
|
|
validate_value(opts->name, argument, option_file);
|
Changing all cost calculation to be given in milliseconds
This makes it easier to compare different costs and also allows
the optimizer to optimizer different storage engines more reliably.
- Added tests/check_costs.pl, a tool to verify optimizer cost calculations.
- Most engine costs has been found with this program. All steps to
calculate the new costs are documented in Docs/optimizer_costs.txt
- User optimizer_cost variables are given in microseconds (as individual
costs can be very small). Internally they are stored in ms.
- Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost
(9 ms) to common SSD cost (400MB/sec).
- Removed cost calculations for hard disks (rotation etc).
- Changed the following handler functions to return IO_AND_CPU_COST.
This makes it easy to apply different cost modifiers in ha_..time()
functions for io and cpu costs.
- scan_time()
- rnd_pos_time() & rnd_pos_call_time()
- keyread_time()
- Enhanched keyread_time() to calculate the full cost of reading of a set
of keys with a given number of ranges and optional number of blocks that
need to be accessed.
- Removed read_time() as keyread_time() + rnd_pos_time() can do the same
thing and more.
- Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks.
Used heap table costs for json_table. The rest are using default engine
costs.
- Added the following new optimizer variables:
- optimizer_disk_read_ratio
- optimizer_disk_read_cost
- optimizer_key_lookup_cost
- optimizer_row_lookup_cost
- optimizer_row_next_find_cost
- optimizer_scan_cost
- Moved all engine specific cost to OPTIMIZER_COSTS structure.
- Changed costs to use 'records_out' instead of 'records_read' when
recalculating costs.
- Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h.
This allows one to change costs without having to compile a lot of
files.
- Updated costs for filter lookup.
- Use a better cost estimate in best_extension_by_limited_search()
for the sorting cost.
- Fixed previous issues with 'filtered' explain column as we are now
using 'records_out' (min rows seen for table) to calculate filtering.
This greatly simplifies the filtering code in
JOIN_TAB::save_explain_data().
This change caused a lot of queries to be optimized differently than
before, which exposed different issues in the optimizer that needs to
be fixed. These fixes are in the following commits. To not have to
change the same test case over and over again, the changes in the test
cases are done in a single commit after all the critical change sets
are done.
InnoDB changes:
- Updated InnoDB to not divide big range cost with 2.
- Added cost for InnoDB (innobase_update_optimizer_costs()).
- Don't mark clustered primary key with HA_KEYREAD_ONLY. This will
prevent that the optimizer is trying to use index-only scans on
the clustered key.
- Disabled ha_innobase::scan_time() and ha_innobase::read_time() and
ha_innobase::rnd_pos_time() as the default engine cost functions now
works good for InnoDB.
Other things:
- Added --show-query-costs (\Q) option to mysql.cc to show the query
cost after each query (good when working with query costs).
- Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust
the value that user is given. This is used to change cost from
microseconds (user input) to milliseconds (what the server is
internally using).
- Added include/my_tracker.h ; Useful include file to quickly test
costs of a function.
- Use handler::set_table() in all places instead of 'table= arg'.
- Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and
shown in microseconds for the user but stored as milliseconds.
This is to make the numbers easier to read for the user (less
pre-zeros). Implemented in 'Sys_var_optimizer_cost' class.
- In test_quick_select() do not use index scans if 'no_keyread' is set
for the table. This is what we do in other places of the server.
- Added THD parameter to Unique::get_use_cost() and
check_index_intersect_extension() and similar functions to be able
to provide costs to called functions.
- Changed 'records' to 'rows' in optimizer_trace.
- Write more information to optimizer_trace.
- Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3)
to calculate usage space of keys in b-trees. (Before we used numeric
constants).
- Removed code that assumed that b-trees has similar costs as binary
trees. Replaced with engine calls that returns the cost.
- Added Bitmap::find_first_bit()
- Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia).
- Added records_init and records_after_filter to POSITION to remember
more of what best_access_patch() calculates.
- table_after_join_selectivity() changed to recalculate 'records_out'
based on the new fields from best_access_patch()
Bug fixes:
- Some queries did not update last_query_cost (was 0). Fixed by moving
setting thd->...last_query_cost in JOIN::optimize().
- Write '0' as number of rows for const tables with a matching row.
Some internals:
- Engine cost are stored in OPTIMIZER_COSTS structure. When a
handlerton is created, we also created a new cost variable for the
handlerton. We also create a new variable if the user changes a
optimizer cost for a not yet loaded handlerton either with command
line arguments or with SET
@@global.engine.optimizer_cost_variable=xx.
- There are 3 global OPTIMIZER_COSTS variables:
default_optimizer_costs The default costs + changes from the
command line without an engine specifier.
heap_optimizer_costs Heap table costs, used for temporary tables
tmp_table_optimizer_costs The cost for the default on disk internal
temporary table (MyISAM or Aria)
- The engine cost for a table is stored in table_share. To speed up
accesses the handler has a pointer to this. The cost is copied
to the table on first access. If one wants to change the cost one
must first update the global engine cost and then do a FLUSH TABLES.
This was done to be able to access the costs for an open table
without any locks.
- When a handlerton is created, the cost are updated the following way:
See sql/keycaches.cc for details:
- Use 'default_optimizer_costs' as a base
- Call hton->update_optimizer_costs() to override with the engines
default costs.
- Override the costs that the user has specified for the engine.
- One handler open, copy the engine cost from handlerton to TABLE_SHARE.
- Call handler::update_optimizer_costs() to allow the engine to update
cost for this particular table.
- There are two costs stored in THD. These are copied to the handler
when the table is used in a query:
- optimizer_where_cost
- optimizer_scan_setup_cost
- Simply code in best_access_path() by storing all cost result in a
structure. (Idea/Suggestion by Igor)
2022-08-11 12:05:23 +02:00
|
|
|
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
ret:
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"%s: Error while setting value '%s' to '%s'",
|
|
|
|
my_progname, argument, opts->name);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(res);
|
2002-05-07 19:35:06 +02:00
|
|
|
}
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2005-10-06 21:09:15 +02:00
|
|
|
/*
|
|
|
|
Find option
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
findopt()
|
|
|
|
optpat Prefix of option to find (with - or _)
|
|
|
|
length Length of optpat
|
|
|
|
opt_res Options
|
|
|
|
ffname Place for pointer to first found name
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Go through all options in the my_option struct. Return number
|
|
|
|
of options found that match the pattern and in the argument
|
|
|
|
list the option found, if any. In case of ambiguous option, store
|
|
|
|
the name in ffname argument
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 No matching options
|
|
|
|
# Number of matching options
|
|
|
|
ffname points to first matching option
|
2002-01-25 22:34:37 +01:00
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
static int findopt(char *optpat, uint length,
|
|
|
|
const struct my_option **opt_res,
|
Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.
One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.
There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
BUILD/SETUP.sh:
Remove flags that are implied by -Wall and -Wextra.
Do not warn about unused parameters in C++.
BUILD/check-cpu:
Print only the compiler version instead of verbose banner.
Although the option is gcc specific, the check was only
being used for GCC specific checks anyway.
client/mysql.cc:
bcmp is no longer defined.
client/mysqltest.cc:
Pass a string to function expecting a format string.
Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
Always define _GNU_SOURCE when compiling GNU readline.
Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
Condition for the code to be meaningful.
configure.in:
Remove check for bcmp.
extra/comp_err.c:
Use appropriate type.
extra/replace.c:
Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
Do not ignore the return value of fgets. Retrieve the file
position if fgets succeed -- if it fails, the function will
bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
Use a single array instead of accessing positions of the sbox_
through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
Do not define type within a anonymous union.
Use a variable to return a value instead of
leaving the result in a register -- compiler
does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
Define handler for pure virtual functions.
Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
Function must have C language linkage.
include/m_string.h:
Remove check which relied on bcmp being defined -- they weren't
being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
Remove bogus helpers which were used only in a few files and
were causing warnings about dead code.
include/my_global.h:
Due to G++ bug, always silence false-positive uninitialized
variables warnings when compiling C++ code with G++.
Remove bogus helper.
libmysql/Makefile.shared:
Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
Leave space of the ending nul.
mysys/mf_pack.c:
Replace bcmp with memcmp.
mysys/my_bitmap.c:
Dead code removal.
mysys/my_gethwaddr.c:
Remove unused variable.
mysys/my_getopt.c:
Silence bogus uninitialized variable warning.
Do not cast away the constant qualifier.
mysys/safemalloc.c:
Cast to expected type.
mysys/thr_lock.c:
Silence bogus uninitialized variable warning.
sql/field.cc:
Replace bogus helper with a more appropriate logic which is
used throughout the code.
sql/item.cc:
Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
Simplify code to avoid signedness related warnings.
sql/log_event.cc:
Replace use of bcmp with memcmp.
No need to use helpers for simple bit operations.
sql/log_event_old.cc:
Replace bmove_align with memcpy.
sql/mysqld.cc:
Move use declaration of variable to the ifdef block where it
is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
Cast to expected type and silence bogus warning.
sql/sql_class.h:
Don't use enum values as bit flags, the supposed type safety is
bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
Only declare variable when necessary.
sql/unireg.h:
Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
Silence bogus warning.
storage/myisam/mi_open.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
storage/myisam/mi_page.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
strings/bcmp.c:
Remove built-in bcmp.
strings/ctype-ucs2.c:
Silence bogus warning.
tests/mysql_client_test.c:
Use a appropriate type as expected by simple_command().
2010-07-02 20:30:47 +02:00
|
|
|
const char **ffname)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2004-01-14 03:58:37 +01:00
|
|
|
uint count;
|
Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.
One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.
There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
BUILD/SETUP.sh:
Remove flags that are implied by -Wall and -Wextra.
Do not warn about unused parameters in C++.
BUILD/check-cpu:
Print only the compiler version instead of verbose banner.
Although the option is gcc specific, the check was only
being used for GCC specific checks anyway.
client/mysql.cc:
bcmp is no longer defined.
client/mysqltest.cc:
Pass a string to function expecting a format string.
Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
Always define _GNU_SOURCE when compiling GNU readline.
Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
Condition for the code to be meaningful.
configure.in:
Remove check for bcmp.
extra/comp_err.c:
Use appropriate type.
extra/replace.c:
Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
Do not ignore the return value of fgets. Retrieve the file
position if fgets succeed -- if it fails, the function will
bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
Use a single array instead of accessing positions of the sbox_
through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
Do not define type within a anonymous union.
Use a variable to return a value instead of
leaving the result in a register -- compiler
does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
Define handler for pure virtual functions.
Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
Function must have C language linkage.
include/m_string.h:
Remove check which relied on bcmp being defined -- they weren't
being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
Remove bogus helpers which were used only in a few files and
were causing warnings about dead code.
include/my_global.h:
Due to G++ bug, always silence false-positive uninitialized
variables warnings when compiling C++ code with G++.
Remove bogus helper.
libmysql/Makefile.shared:
Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
Leave space of the ending nul.
mysys/mf_pack.c:
Replace bcmp with memcmp.
mysys/my_bitmap.c:
Dead code removal.
mysys/my_gethwaddr.c:
Remove unused variable.
mysys/my_getopt.c:
Silence bogus uninitialized variable warning.
Do not cast away the constant qualifier.
mysys/safemalloc.c:
Cast to expected type.
mysys/thr_lock.c:
Silence bogus uninitialized variable warning.
sql/field.cc:
Replace bogus helper with a more appropriate logic which is
used throughout the code.
sql/item.cc:
Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
Simplify code to avoid signedness related warnings.
sql/log_event.cc:
Replace use of bcmp with memcmp.
No need to use helpers for simple bit operations.
sql/log_event_old.cc:
Replace bmove_align with memcpy.
sql/mysqld.cc:
Move use declaration of variable to the ifdef block where it
is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
Cast to expected type and silence bogus warning.
sql/sql_class.h:
Don't use enum values as bit flags, the supposed type safety is
bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
Only declare variable when necessary.
sql/unireg.h:
Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
Silence bogus warning.
storage/myisam/mi_open.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
storage/myisam/mi_page.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
strings/bcmp.c:
Remove built-in bcmp.
strings/ctype-ucs2.c:
Silence bogus warning.
tests/mysql_client_test.c:
Use a appropriate type as expected by simple_command().
2010-07-02 20:30:47 +02:00
|
|
|
const struct my_option *opt= *opt_res;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("findopt");
|
2002-01-25 22:34:37 +01:00
|
|
|
|
2002-01-31 03:36:58 +01:00
|
|
|
for (count= 0; opt->name; opt++)
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-07-23 17:31:22 +02:00
|
|
|
if (!getopt_compare_strings(opt->name, optpat, length)) /* match found */
|
2002-01-25 22:34:37 +01:00
|
|
|
{
|
2002-01-30 04:08:17 +01:00
|
|
|
(*opt_res)= opt;
|
2002-07-23 17:31:22 +02:00
|
|
|
if (!opt->name[length]) /* Exact match */
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(1);
|
2013-06-26 11:19:02 +02:00
|
|
|
|
2015-01-07 12:13:21 +01:00
|
|
|
if (!my_getopt_prefix_matching)
|
|
|
|
continue;
|
|
|
|
|
2005-10-06 21:09:15 +02:00
|
|
|
if (!count)
|
|
|
|
{
|
Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.
One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.
There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
BUILD/SETUP.sh:
Remove flags that are implied by -Wall and -Wextra.
Do not warn about unused parameters in C++.
BUILD/check-cpu:
Print only the compiler version instead of verbose banner.
Although the option is gcc specific, the check was only
being used for GCC specific checks anyway.
client/mysql.cc:
bcmp is no longer defined.
client/mysqltest.cc:
Pass a string to function expecting a format string.
Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
Always define _GNU_SOURCE when compiling GNU readline.
Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
Condition for the code to be meaningful.
configure.in:
Remove check for bcmp.
extra/comp_err.c:
Use appropriate type.
extra/replace.c:
Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
Do not ignore the return value of fgets. Retrieve the file
position if fgets succeed -- if it fails, the function will
bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
Use a single array instead of accessing positions of the sbox_
through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
Do not define type within a anonymous union.
Use a variable to return a value instead of
leaving the result in a register -- compiler
does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
Define handler for pure virtual functions.
Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
Function must have C language linkage.
include/m_string.h:
Remove check which relied on bcmp being defined -- they weren't
being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
Remove bogus helpers which were used only in a few files and
were causing warnings about dead code.
include/my_global.h:
Due to G++ bug, always silence false-positive uninitialized
variables warnings when compiling C++ code with G++.
Remove bogus helper.
libmysql/Makefile.shared:
Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
Leave space of the ending nul.
mysys/mf_pack.c:
Replace bcmp with memcmp.
mysys/my_bitmap.c:
Dead code removal.
mysys/my_gethwaddr.c:
Remove unused variable.
mysys/my_getopt.c:
Silence bogus uninitialized variable warning.
Do not cast away the constant qualifier.
mysys/safemalloc.c:
Cast to expected type.
mysys/thr_lock.c:
Silence bogus uninitialized variable warning.
sql/field.cc:
Replace bogus helper with a more appropriate logic which is
used throughout the code.
sql/item.cc:
Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
Simplify code to avoid signedness related warnings.
sql/log_event.cc:
Replace use of bcmp with memcmp.
No need to use helpers for simple bit operations.
sql/log_event_old.cc:
Replace bmove_align with memcpy.
sql/mysqld.cc:
Move use declaration of variable to the ifdef block where it
is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
Cast to expected type and silence bogus warning.
sql/sql_class.h:
Don't use enum values as bit flags, the supposed type safety is
bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
Only declare variable when necessary.
sql/unireg.h:
Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
Silence bogus warning.
storage/myisam/mi_open.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
storage/myisam/mi_page.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
strings/bcmp.c:
Remove built-in bcmp.
strings/ctype-ucs2.c:
Silence bogus warning.
tests/mysql_client_test.c:
Use a appropriate type as expected by simple_command().
2010-07-02 20:30:47 +02:00
|
|
|
/* We only need to know one prev */
|
2005-10-06 21:09:15 +02:00
|
|
|
count= 1;
|
Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.
One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.
There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
BUILD/SETUP.sh:
Remove flags that are implied by -Wall and -Wextra.
Do not warn about unused parameters in C++.
BUILD/check-cpu:
Print only the compiler version instead of verbose banner.
Although the option is gcc specific, the check was only
being used for GCC specific checks anyway.
client/mysql.cc:
bcmp is no longer defined.
client/mysqltest.cc:
Pass a string to function expecting a format string.
Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
Always define _GNU_SOURCE when compiling GNU readline.
Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
Condition for the code to be meaningful.
configure.in:
Remove check for bcmp.
extra/comp_err.c:
Use appropriate type.
extra/replace.c:
Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
Do not ignore the return value of fgets. Retrieve the file
position if fgets succeed -- if it fails, the function will
bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
Use a single array instead of accessing positions of the sbox_
through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
Do not define type within a anonymous union.
Use a variable to return a value instead of
leaving the result in a register -- compiler
does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
Define handler for pure virtual functions.
Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
Function must have C language linkage.
include/m_string.h:
Remove check which relied on bcmp being defined -- they weren't
being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
Remove bogus helpers which were used only in a few files and
were causing warnings about dead code.
include/my_global.h:
Due to G++ bug, always silence false-positive uninitialized
variables warnings when compiling C++ code with G++.
Remove bogus helper.
libmysql/Makefile.shared:
Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
Leave space of the ending nul.
mysys/mf_pack.c:
Replace bcmp with memcmp.
mysys/my_bitmap.c:
Dead code removal.
mysys/my_gethwaddr.c:
Remove unused variable.
mysys/my_getopt.c:
Silence bogus uninitialized variable warning.
Do not cast away the constant qualifier.
mysys/safemalloc.c:
Cast to expected type.
mysys/thr_lock.c:
Silence bogus uninitialized variable warning.
sql/field.cc:
Replace bogus helper with a more appropriate logic which is
used throughout the code.
sql/item.cc:
Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
Simplify code to avoid signedness related warnings.
sql/log_event.cc:
Replace use of bcmp with memcmp.
No need to use helpers for simple bit operations.
sql/log_event_old.cc:
Replace bmove_align with memcpy.
sql/mysqld.cc:
Move use declaration of variable to the ifdef block where it
is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
Cast to expected type and silence bogus warning.
sql/sql_class.h:
Don't use enum values as bit flags, the supposed type safety is
bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
Only declare variable when necessary.
sql/unireg.h:
Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
Silence bogus warning.
storage/myisam/mi_open.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
storage/myisam/mi_page.c:
Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
char.
strings/bcmp.c:
Remove built-in bcmp.
strings/ctype-ucs2.c:
Silence bogus warning.
tests/mysql_client_test.c:
Use a appropriate type as expected by simple_command().
2010-07-02 20:30:47 +02:00
|
|
|
*ffname= opt->name;
|
2005-10-06 21:09:15 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(*ffname, opt->name))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The above test is to not count same option twice
|
|
|
|
(see mysql.cc, option "help")
|
|
|
|
*/
|
2004-01-14 03:58:37 +01:00
|
|
|
count++;
|
2005-10-06 21:09:15 +02:00
|
|
|
}
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 12:13:21 +01:00
|
|
|
|
|
|
|
if (count == 1)
|
|
|
|
my_getopt_error_reporter(INFORMATION_LEVEL,
|
|
|
|
"Using unique option prefix '%.*s' is error-prone "
|
|
|
|
"and can break in the future. "
|
|
|
|
"Please use the full name '%s' instead.",
|
|
|
|
length, optpat, *ffname);
|
|
|
|
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(count);
|
2002-01-25 22:34:37 +01:00
|
|
|
}
|
2002-01-30 04:08:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
function: compare_strings
|
|
|
|
|
|
|
|
Works like strncmp, other than 1.) considers '-' and '_' the same.
|
|
|
|
2.) Returns -1 if strings differ, 0 if they are equal
|
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
my_bool getopt_compare_strings(register const char *s, register const char *t,
|
2002-01-30 04:08:17 +01:00
|
|
|
uint length)
|
|
|
|
{
|
|
|
|
char const *end= s + length;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("getopt_compare_strings");
|
|
|
|
|
2002-01-30 04:08:17 +01:00
|
|
|
for (;s != end ; s++, t++)
|
|
|
|
{
|
|
|
|
if ((*s != '-' ? *s : '_') != (*t != '-' ? *t : '_'))
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(1);
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
/*
|
|
|
|
function: eval_num_suffix
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2017-12-05 02:39:37 +01:00
|
|
|
Transforms suffix like k/m/g/t/p/e to their real value.
|
2017-01-10 05:38:04 +01:00
|
|
|
*/
|
|
|
|
|
2017-12-05 02:39:37 +01:00
|
|
|
static inline ulonglong eval_num_suffix(char *suffix, int *error)
|
2017-01-10 05:38:04 +01:00
|
|
|
{
|
2017-12-05 02:39:37 +01:00
|
|
|
switch (*suffix) {
|
|
|
|
case '\0':
|
|
|
|
return 1ULL;
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
return 1ULL << 10;
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
return 1ULL << 20;
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
return 1ULL << 30;
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
|
|
|
return 1ULL << 40;
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
return 1ULL << 50;
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
return 1ULL << 60;
|
|
|
|
default:
|
2024-03-09 00:53:24 +01:00
|
|
|
*error= EXIT_UNKNOWN_SUFFIX;
|
2017-12-05 02:39:37 +01:00
|
|
|
return 0ULL;
|
2017-01-10 05:38:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
function: eval_num_suffix_ll
|
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
Transforms a number with a suffix to real number. Suffix can
|
2017-12-05 02:39:37 +01:00
|
|
|
be k|K for kilo, m|M for mega, etc.
|
2002-01-30 04:08:17 +01:00
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2017-01-10 05:38:04 +01:00
|
|
|
static longlong eval_num_suffix_ll(char *argument,
|
|
|
|
int *error, char *option_name)
|
2002-01-30 04:08:17 +01:00
|
|
|
{
|
|
|
|
char *endchar;
|
|
|
|
longlong num;
|
2017-01-10 05:38:04 +01:00
|
|
|
DBUG_ENTER("eval_num_suffix_ll");
|
2011-07-10 20:21:18 +02:00
|
|
|
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
*error= 0;
|
2007-10-04 10:34:00 +02:00
|
|
|
errno= 0;
|
2002-05-07 19:35:06 +02:00
|
|
|
num= strtoll(argument, &endchar, 10);
|
2007-10-04 10:34:00 +02:00
|
|
|
if (errno == ERANGE)
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
2024-04-17 13:14:58 +02:00
|
|
|
"Integer value out of range for int64:"
|
|
|
|
" '%s' for %s",
|
|
|
|
argument, option_name);
|
2024-03-09 00:53:24 +01:00
|
|
|
*error= EXIT_ARGUMENT_INVALID;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2007-10-04 10:34:00 +02:00
|
|
|
}
|
2017-01-10 05:38:04 +01:00
|
|
|
num*= eval_num_suffix(endchar, error);
|
|
|
|
if (*error)
|
2024-03-09 00:53:24 +01:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"Unknown suffix '%c' used for variable '%s' (value '%s'). "
|
|
|
|
"Legal suffix characters are: K, M, G, T, P, E",
|
|
|
|
*endchar, option_name, argument);
|
2017-01-10 05:38:04 +01:00
|
|
|
DBUG_RETURN(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
function: eval_num_suffix_ull
|
|
|
|
|
|
|
|
Transforms a number with a suffix to positive Integer. Suffix can
|
2017-12-05 02:39:37 +01:00
|
|
|
be k|K for kilo, m|M for mega, etc.
|
2017-01-10 05:38:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
static ulonglong eval_num_suffix_ull(char *argument,
|
|
|
|
int *error, char *option_name)
|
|
|
|
{
|
|
|
|
char *endchar;
|
|
|
|
ulonglong num;
|
|
|
|
DBUG_ENTER("eval_num_suffix_ull");
|
|
|
|
|
2020-04-11 07:03:54 +02:00
|
|
|
if (*argument == '-')
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"Incorrect unsigned value: '%s' for %s",
|
|
|
|
argument, option_name);
|
2024-04-17 13:14:58 +02:00
|
|
|
*error= EXIT_ARGUMENT_INVALID;
|
2020-04-11 07:03:54 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2017-01-10 05:38:04 +01:00
|
|
|
*error= 0;
|
|
|
|
errno= 0;
|
|
|
|
num= strtoull(argument, &endchar, 10);
|
|
|
|
if (errno == ERANGE)
|
|
|
|
{
|
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
2024-04-17 13:14:58 +02:00
|
|
|
"Integer value out of range for uint64:"
|
|
|
|
" '%s' for %s",
|
2020-04-11 07:03:54 +02:00
|
|
|
argument, option_name);
|
2024-03-09 00:53:24 +01:00
|
|
|
*error= EXIT_ARGUMENT_INVALID;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(0);
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
2017-01-10 05:38:04 +01:00
|
|
|
num*= eval_num_suffix(endchar, error);
|
|
|
|
if (*error)
|
2020-04-11 07:03:54 +02:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
2024-04-17 13:14:58 +02:00
|
|
|
"Unknown suffix '%c' used for variable '%s'"
|
|
|
|
" (value '%s')."
|
|
|
|
" Legal suffix characters are: K, M, G, T, P, E",
|
2020-04-11 07:03:54 +02:00
|
|
|
*endchar, option_name, argument);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(num);
|
2002-05-07 19:35:06 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 05:38:04 +01:00
|
|
|
|
2007-10-13 20:25:53 +02:00
|
|
|
/*
|
2002-05-07 19:35:06 +02:00
|
|
|
function: getopt_ll
|
|
|
|
|
|
|
|
Evaluates and returns the value that user gave as an argument
|
|
|
|
to a variable. Recognizes (case insensitive) K as KILO, M as MEGA
|
|
|
|
and G as GIGA bytes. Some values must be in certain blocks, as
|
|
|
|
defined in the given my_option struct, this function will check
|
|
|
|
that those values are honored.
|
|
|
|
In case of an error, set error value in *err.
|
|
|
|
*/
|
|
|
|
|
2003-01-05 19:18:49 +01:00
|
|
|
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
|
2002-05-07 19:35:06 +02:00
|
|
|
{
|
2017-01-10 05:38:04 +01:00
|
|
|
longlong num=eval_num_suffix_ll(arg, err, (char*) optp->name);
|
2024-02-25 03:03:44 +01:00
|
|
|
if (*err)
|
|
|
|
return(0);
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
return getopt_ll_limit_value(num, optp, NULL);
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
function: getopt_ll_limit_value
|
|
|
|
|
|
|
|
Applies min/max/block_size to a numeric value of an option.
|
|
|
|
Returns "fixed" value.
|
|
|
|
*/
|
|
|
|
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
longlong getopt_ll_limit_value(longlong num, const struct my_option *optp,
|
2008-02-18 23:29:39 +01:00
|
|
|
my_bool *fix)
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
{
|
|
|
|
longlong old= num;
|
2008-02-18 23:29:39 +01:00
|
|
|
my_bool adjusted= FALSE;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
char buf1[255], buf2[255];
|
2004-03-06 09:43:35 +01:00
|
|
|
ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("getopt_ll_limit_value");
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
|
|
|
|
if (num > 0 && ((ulonglong) num > (ulonglong) optp->max_value) &&
|
2004-03-06 09:43:35 +01:00
|
|
|
optp->max_value) /* if max value is not set -> no upper limit */
|
2007-10-04 10:34:00 +02:00
|
|
|
{
|
2005-10-25 19:10:53 +02:00
|
|
|
num= (ulonglong) optp->max_value;
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((optp->var_type & GET_TYPE_MASK)) {
|
|
|
|
case GET_INT:
|
|
|
|
if (num > (longlong) INT_MAX)
|
|
|
|
{
|
|
|
|
num= ((longlong) INT_MAX);
|
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GET_LONG:
|
|
|
|
#if SIZEOF_LONG < SIZEOF_LONG_LONG
|
|
|
|
if (num > (longlong) LONG_MAX)
|
|
|
|
{
|
|
|
|
num= ((longlong) LONG_MAX);
|
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT((optp->var_type & GET_TYPE_MASK) == GET_LL);
|
|
|
|
break;
|
2007-10-04 10:34:00 +02:00
|
|
|
}
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
num= (num / block_size);
|
2004-03-06 09:43:35 +01:00
|
|
|
num= (longlong) (num * block_size);
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
|
|
|
|
if (num < optp->min_value)
|
|
|
|
{
|
|
|
|
num= optp->min_value;
|
2009-03-16 16:11:45 +01:00
|
|
|
if (old < optp->min_value)
|
|
|
|
adjusted= TRUE;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
}
|
|
|
|
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
if (fix)
|
2009-12-22 10:35:56 +01:00
|
|
|
*fix= old != num;
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
else if (adjusted)
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
|
|
|
"option '%s': signed value %s adjusted to %s",
|
|
|
|
optp->name, llstr(old, buf1), llstr(num, buf2));
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(num);
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
/*
|
|
|
|
function: getopt_ull
|
|
|
|
|
|
|
|
This is the same as getopt_ll, but is meant for unsigned long long
|
|
|
|
values.
|
|
|
|
*/
|
|
|
|
|
2003-01-05 19:18:49 +01:00
|
|
|
static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err)
|
2002-05-07 19:35:06 +02:00
|
|
|
{
|
2017-01-10 05:38:04 +01:00
|
|
|
ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name);
|
2024-02-25 03:03:44 +01:00
|
|
|
if (*err)
|
|
|
|
return(0);
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
return getopt_ull_limit_value(num, optp, NULL);
|
2002-07-23 17:31:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
|
2008-02-18 23:29:39 +01:00
|
|
|
my_bool *fix)
|
2002-07-23 17:31:22 +02:00
|
|
|
{
|
2008-02-18 23:29:39 +01:00
|
|
|
my_bool adjusted= FALSE;
|
2007-12-04 01:17:52 +01:00
|
|
|
ulonglong old= num;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
char buf1[255], buf2[255];
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("getopt_ull_limit_value");
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
|
2003-06-12 18:46:12 +02:00
|
|
|
if ((ulonglong) num > (ulonglong) optp->max_value &&
|
2002-07-23 17:31:22 +02:00
|
|
|
optp->max_value) /* if max value is not set -> no upper limit */
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
{
|
2003-06-12 18:46:12 +02:00
|
|
|
num= (ulonglong) optp->max_value;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((optp->var_type & GET_TYPE_MASK)) {
|
|
|
|
case GET_UINT:
|
|
|
|
if (num > (ulonglong) UINT_MAX)
|
|
|
|
{
|
|
|
|
num= ((ulonglong) UINT_MAX);
|
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GET_ULONG:
|
|
|
|
#if SIZEOF_LONG < SIZEOF_LONG_LONG
|
|
|
|
if (num > (ulonglong) ULONG_MAX)
|
|
|
|
{
|
|
|
|
num= ((ulonglong) ULONG_MAX);
|
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT((optp->var_type & GET_TYPE_MASK) == GET_ULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
if (optp->block_size > 1)
|
|
|
|
{
|
|
|
|
num/= (ulonglong) optp->block_size;
|
|
|
|
num*= (ulonglong) optp->block_size;
|
|
|
|
}
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
|
2002-05-07 19:35:06 +02:00
|
|
|
if (num < (ulonglong) optp->min_value)
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
{
|
2002-05-07 19:35:06 +02:00
|
|
|
num= (ulonglong) optp->min_value;
|
2009-03-17 18:24:35 +01:00
|
|
|
if (old < (ulonglong) optp->min_value)
|
2009-03-16 16:11:45 +01:00
|
|
|
adjusted= TRUE;
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
}
|
|
|
|
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
if (fix)
|
2009-12-22 10:35:56 +01:00
|
|
|
*fix= old != num;
|
Bug#31177: Server variables can't be set to their current values
5.1+ specific fixes (plugins etc.)
include/my_getopt.h:
make both ull and ll global
mysql-test/r/index_merge_myisam.result:
we throw warnings to the client, yea, verily
mysql-test/r/innodb.result:
we throw warnings to the client, yea, verily
mysql-test/r/variables.result:
we throw warnings to the client, yea, verily
mysql-test/t/variables.test:
correct result, is multiple of variable's block_size now
mysys/my_getopt.c:
export getopt_ll_limit_value(), check for integer wrap-around
in it, same as in ull variant. Only print warnings to reporter
when caller didn't ask for diagnostics, otherwise assume caller
will handle any warnings (id est, throw them client-wards)
sql/mysqld.cc:
correct signedness of "concurrent-insert"
sql/sql_plugin.cc:
Throw sys-var out-of-range warnings client-wards for
plugins, too.
2007-12-01 19:55:06 +01:00
|
|
|
else if (adjusted)
|
Bug#31177: Server variables can't be set to their current values
Default values of variables were not subject to upper/lower bounds
and step, while setting variables was. Bounds and step are also
applied to defaults now; defaults are corrected quietly, values
given by the user are corrected, and a correction-warning is thrown
as needed. Lastly, very large values could wrap around, starting
from 0 again. They are bounded at the maximum value for the
respective data-type now if no lower maximum is specified in the
variable's definition.
client/mysql.cc:
correct maxima in options array
client/mysqltest.c:
adjust minimum for "sleep" option so default value is no longer
out of bounds.
include/m_string.h:
ullstr() - the unsigned brother of llstr()
include/my_getopt.h:
Flag if we bounded the value (that is, correct anything aside from
making value a multiple of block-size)
mysql-test/r/delayed.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/index_merge.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/innodb_mysql.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/key_cache.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/packet.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/ps.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/subselect.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/type_bit_innodb.result:
We throw a warning now when we adjust out of range parameters.
mysql-test/r/variables.result:
correct results: bounds and step apply to variables' default values, too
mysql-test/t/variables.test:
correct results: bounds and step apply to variables' default values, too
mysys/my_getopt.c:
- apply bounds/step to default values of variables (based on work by serg)
- print complaints about incorrect values for variables (truncation etc.,
by requestion of consulting)
- if no lower maximum is specified in variable definition, bound unsigned
values at their maximum to prevent wrap-around
- some calls to error_reporter had a \n, some didn't. remove \n from calls,
let reporter-function handle it, so the default reporter behaves like that
in mysqld
sql/mysql_priv.h:
correct RANGE_ALLOC_BLOCK_SIZE (cleared with monty)
sql/mysqld.cc:
correct maxima to correct data-type.
correct minima where higher than default.
correct range-alloc-block-size.
correct inno variables so GET_* corresponds to actual variable's type.
sql/set_var.cc:
When the new value for a variable is out of bounds, we'll send the
client a warning (but not if the value was simply not a multiple of
'blocksize'). sys_var_thd_ulong had this, sys_var_long_ptr_global
didn't; broken out and streamlined to avoid duplication of code.
strings/llstr.c:
ullstr() - the unsigned brother of llstr()
2007-11-30 06:32:04 +01:00
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
|
|
|
"option '%s': unsigned value %s adjusted to %s",
|
|
|
|
optp->name, ullstr(old, buf1), ullstr(num, buf2));
|
2011-04-25 17:22:25 +02:00
|
|
|
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(num);
|
2002-05-07 19:35:06 +02:00
|
|
|
}
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
double getopt_double_limit_value(double num, const struct my_option *optp,
|
|
|
|
my_bool *fix)
|
|
|
|
{
|
|
|
|
my_bool adjusted= FALSE;
|
|
|
|
double old= num;
|
2013-05-19 20:08:06 +02:00
|
|
|
double min, max;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("getopt_double_limit_value");
|
|
|
|
|
2013-05-19 20:08:06 +02:00
|
|
|
max= getopt_ulonglong2double(optp->max_value);
|
|
|
|
min= getopt_ulonglong2double(optp->min_value);
|
|
|
|
if (max && num > max)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2013-05-19 20:08:06 +02:00
|
|
|
num= max;
|
2009-12-22 10:35:56 +01:00
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
2013-05-19 20:08:06 +02:00
|
|
|
if (num < min)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2013-05-19 20:08:06 +02:00
|
|
|
num= min;
|
2009-12-22 10:35:56 +01:00
|
|
|
adjusted= TRUE;
|
|
|
|
}
|
|
|
|
if (fix)
|
|
|
|
*fix= adjusted;
|
|
|
|
else if (adjusted)
|
|
|
|
my_getopt_error_reporter(WARNING_LEVEL,
|
|
|
|
"option '%s': value %g adjusted to %g",
|
|
|
|
optp->name, old, num);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_RETURN(num);
|
2009-12-22 10:35:56 +01:00
|
|
|
}
|
2002-01-30 04:08:17 +01:00
|
|
|
|
2007-07-30 10:33:50 +02:00
|
|
|
/*
|
|
|
|
Get double value withing ranges
|
|
|
|
|
|
|
|
Evaluates and returns the value that user gave as an argument to a variable.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
decimal value of arg
|
|
|
|
|
|
|
|
In case of an error, prints an error message and sets *err to
|
|
|
|
EXIT_ARGUMENT_INVALID. Otherwise err is not touched
|
|
|
|
*/
|
|
|
|
|
|
|
|
static double getopt_double(char *arg, const struct my_option *optp, int *err)
|
|
|
|
{
|
|
|
|
double num;
|
|
|
|
int error;
|
|
|
|
char *end= arg + 1000; /* Big enough as *arg is \0 terminated */
|
|
|
|
num= my_strtod(arg, &end, &error);
|
|
|
|
if (end[0] != 0 || error)
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_getopt_error_reporter(ERROR_LEVEL,
|
|
|
|
"Invalid decimal value for option '%s'\n", optp->name);
|
2007-07-30 10:33:50 +02:00
|
|
|
*err= EXIT_ARGUMENT_INVALID;
|
|
|
|
return 0.0;
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
return getopt_double_limit_value(num, optp, NULL);
|
2007-07-30 10:33:50 +02:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
/*
|
|
|
|
Init one value to it's default values
|
|
|
|
|
|
|
|
SYNOPSIS
|
2024-04-21 13:29:31 +02:00
|
|
|
my_getopt_init_one_value()
|
2007-12-20 13:10:07 +01:00
|
|
|
option Option to initialize
|
2007-10-13 20:25:53 +02:00
|
|
|
value Pointer to variable
|
2003-11-18 12:47:27 +01:00
|
|
|
*/
|
|
|
|
|
2024-04-21 13:29:31 +02:00
|
|
|
void my_getopt_init_one_value(const struct my_option *option, void *variable,
|
|
|
|
longlong value)
|
2003-11-18 12:47:27 +01:00
|
|
|
{
|
2007-04-26 21:26:04 +02:00
|
|
|
DBUG_ENTER("init_one_value");
|
2003-11-18 12:47:27 +01:00
|
|
|
switch ((option->var_type & GET_TYPE_MASK)) {
|
|
|
|
case GET_BOOL:
|
|
|
|
*((my_bool*) variable)= (my_bool) value;
|
|
|
|
break;
|
|
|
|
case GET_INT:
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
*((int*) variable)= (int) getopt_ll_limit_value((int) value, option, NULL);
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
2007-03-02 17:43:45 +01:00
|
|
|
case GET_ENUM:
|
2010-08-04 14:58:09 +02:00
|
|
|
*((ulong*) variable)= (ulong) value;
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
case GET_UINT:
|
|
|
|
*((uint*) variable)= (uint) getopt_ull_limit_value((uint) value, option, NULL);
|
|
|
|
break;
|
2003-11-18 12:47:27 +01:00
|
|
|
case GET_LONG:
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
*((long*) variable)= (long) getopt_ll_limit_value((long) value, option, NULL);
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
|
|
|
case GET_ULONG:
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
*((ulong*) variable)= (ulong) getopt_ull_limit_value((ulong) value, option, NULL);
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
|
|
|
case GET_LL:
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
*((longlong*) variable)= (longlong) getopt_ll_limit_value((longlong) value, option, NULL);
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
|
|
|
case GET_ULL:
|
Bug#31177: Server variables can't be set to their current values
Bounds-checks and blocksize corrections were applied to user-input,
but constants in the server were trusted implicitly. If these values
did not actually meet the requirements, the user could not set change
a variable, then set it back to the (wonky) factory default or maximum
by explicitly specifying it (SET <var>=<value> vs SET <var>=DEFAULT).
Now checks also apply to the server's presets. Wonky values and maxima
get corrected at startup. Consequently all non-offsetted values the user
sees are valid, and users can set the variable to that exact value if
they so desire.
mysql-test/r/read_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysql-test/r/read_rnd_buffer_size_basic.result:
test sets out of bounds value; we now throw a warning for this.
This is a side-effect: before, the maximum was higher than the
value we set here. The value was corrected to block-size, the
maximum was not, hence the value was smaller than the maximum
in this particular case. Now that we align the maxima at startup,
the value in SET is larger than the (corrected) maximum, and we
see a warning in this particular case. "This means we're doing it right."
mysys/my_getopt.c:
Do bounds-checking at start-up time so we'll catch and correct
wonky default values and upper limits.
sql/mysqld.cc:
If 0 is a legal value per the docs, not to mention the default, we shouldn't give 1 as
the lower limit.
storage/innobase/handler/ha_innodb.cc:
We are setting upper bounds here.
~0L gives -1. That is NOT what we want!
2009-01-12 06:32:49 +01:00
|
|
|
*((ulonglong*) variable)= (ulonglong) getopt_ull_limit_value((ulonglong) value, option, NULL);
|
2003-11-18 12:47:27 +01:00
|
|
|
break;
|
2009-10-27 14:16:02 +01:00
|
|
|
case GET_SET:
|
2009-12-22 10:35:56 +01:00
|
|
|
case GET_FLAGSET:
|
2009-10-27 14:16:02 +01:00
|
|
|
*((ulonglong*) variable)= (ulonglong) value;
|
|
|
|
break;
|
2017-07-21 18:56:41 +02:00
|
|
|
case GET_BIT:
|
|
|
|
{
|
|
|
|
ulonglong bit= (option->block_size >= 0 ?
|
|
|
|
option->block_size :
|
|
|
|
-option->block_size);
|
|
|
|
if (option->block_size < 0)
|
|
|
|
value= !value;
|
|
|
|
if (value)
|
|
|
|
(*(ulonglong*)variable)|= bit;
|
|
|
|
else
|
|
|
|
(*(ulonglong*)variable)&= ~bit;
|
|
|
|
break;
|
|
|
|
}
|
2007-07-30 10:33:50 +02:00
|
|
|
case GET_DOUBLE:
|
2013-05-19 20:08:06 +02:00
|
|
|
*((double*) variable)= getopt_ulonglong2double(value);
|
2007-07-30 10:33:50 +02:00
|
|
|
break;
|
2007-04-26 21:26:04 +02:00
|
|
|
case GET_STR:
|
|
|
|
/*
|
|
|
|
Do not clear variable value if it has no default value.
|
|
|
|
The default value may already be set.
|
2007-04-30 18:49:38 +02:00
|
|
|
NOTE: To avoid compiler warnings, we first cast longlong to intptr,
|
|
|
|
so that the value has the same size as a pointer.
|
2007-04-26 21:26:04 +02:00
|
|
|
*/
|
2007-04-30 18:49:38 +02:00
|
|
|
if ((char*) (intptr) value)
|
|
|
|
*((char**) variable)= (char*) (intptr) value;
|
2007-04-26 21:26:04 +02:00
|
|
|
break;
|
|
|
|
case GET_STR_ALLOC:
|
|
|
|
/*
|
|
|
|
Do not clear variable value if it has no default value.
|
|
|
|
The default value may already be set.
|
2007-04-30 18:49:38 +02:00
|
|
|
NOTE: To avoid compiler warnings, we first cast longlong to intptr,
|
|
|
|
so that the value has the same size as a pointer.
|
2007-04-26 21:26:04 +02:00
|
|
|
*/
|
2007-04-30 18:49:38 +02:00
|
|
|
if ((char*) (intptr) value)
|
2007-04-26 21:26:04 +02:00
|
|
|
{
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
client/mysqldump.c:
Pass my_free directly as its signature is compatible with the
callback type -- which wasn't the case for free_table_ent.
2010-07-08 23:20:08 +02:00
|
|
|
char **pstr= (char **) variable;
|
|
|
|
my_free(*pstr);
|
2020-01-29 13:50:26 +01:00
|
|
|
*pstr= my_strdup(key_memory_defaults, (char*) (intptr) value, MYF(MY_WME));
|
2007-04-26 21:26:04 +02:00
|
|
|
}
|
|
|
|
break;
|
2003-11-18 12:47:27 +01:00
|
|
|
default: /* dummy default to avoid compiler warnings */
|
|
|
|
break;
|
|
|
|
}
|
2007-04-26 21:26:04 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-11-18 12:47:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-04 19:55:08 +02:00
|
|
|
/*
|
|
|
|
Init one value to it's default values
|
|
|
|
|
|
|
|
SYNOPSIS
|
2024-04-21 13:29:31 +02:00
|
|
|
fini_one_value()
|
2007-10-04 19:55:08 +02:00
|
|
|
option Option to initialize
|
|
|
|
value Pointer to variable
|
|
|
|
*/
|
|
|
|
|
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.
2010-06-10 22:16:43 +02:00
|
|
|
static void fini_one_value(const struct my_option *option, void *variable,
|
2007-10-04 19:55:08 +02:00
|
|
|
longlong value __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
DBUG_ENTER("fini_one_value");
|
|
|
|
switch ((option->var_type & GET_TYPE_MASK)) {
|
|
|
|
case GET_STR_ALLOC:
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
client/mysqldump.c:
Pass my_free directly as its signature is compatible with the
callback type -- which wasn't the case for free_table_ent.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(*((char**) variable));
|
2007-10-04 19:55:08 +02:00
|
|
|
*((char**) variable)= NULL;
|
|
|
|
break;
|
|
|
|
default: /* dummy default to avoid compiler warnings */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void my_cleanup_options(const struct my_option *options)
|
|
|
|
{
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("my_cleanup_options");
|
2007-10-04 19:55:08 +02:00
|
|
|
init_variables(options, fini_one_value);
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2007-10-04 19:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 20:25:53 +02:00
|
|
|
/*
|
2002-01-30 04:08:17 +01:00
|
|
|
initialize all variables to their default values
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
init_variables()
|
2015-07-06 19:24:14 +02:00
|
|
|
options Array of options
|
|
|
|
func_init_one_value Call this function to init the variable
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
NOTES
|
|
|
|
We will initialize the value that is pointed to by options->value.
|
2009-12-22 10:35:56 +01:00
|
|
|
If the value is of type GET_ASK_ADDR, we will ask for the address
|
2003-11-18 12:47:27 +01:00
|
|
|
for a value and initialize.
|
2002-01-30 04:08:17 +01:00
|
|
|
*/
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2007-10-04 19:55:08 +02:00
|
|
|
static void init_variables(const struct my_option *options,
|
2015-07-06 19:24:14 +02:00
|
|
|
init_func_p func_init_one_value)
|
2002-01-30 04:08:17 +01:00
|
|
|
{
|
2007-04-26 21:26:04 +02:00
|
|
|
DBUG_ENTER("init_variables");
|
2002-02-06 16:22:43 +01:00
|
|
|
for (; options->name; options++)
|
2002-01-30 04:08:17 +01:00
|
|
|
{
|
2010-06-11 03:30:49 +02:00
|
|
|
void *value;
|
2007-04-26 21:26:04 +02:00
|
|
|
DBUG_PRINT("options", ("name: '%s'", options->name));
|
2003-11-18 12:47:27 +01:00
|
|
|
/*
|
|
|
|
We must set u_max_value first as for some variables
|
|
|
|
options->u_max_value == options->value and in this case we want to
|
|
|
|
set the value to default value.
|
|
|
|
*/
|
|
|
|
if (options->u_max_value)
|
2015-07-06 19:24:14 +02:00
|
|
|
func_init_one_value(options, options->u_max_value, options->max_value);
|
2019-09-29 14:38:53 +02:00
|
|
|
value= options->var_type & GET_ASK_ADDR ?
|
|
|
|
(*my_getopt_get_addr)("", 0, options, 0) : options->value;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (value)
|
2015-07-06 19:24:14 +02:00
|
|
|
func_init_one_value(options, value, options->def_value);
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
2007-04-26 21:26:04 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2002-01-30 04:08:17 +01:00
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/** Prints variable or option name, replacing _ with - */
|
|
|
|
static uint print_name(const struct my_option *optp)
|
|
|
|
{
|
|
|
|
const char *s= optp->name;
|
2011-07-10 20:21:18 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (;*s;s++)
|
|
|
|
putchar(*s == '_' ? '-' : *s);
|
2017-09-28 12:38:02 +02:00
|
|
|
return (uint)(s - optp->name);
|
2009-12-22 10:35:56 +01:00
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2014-06-19 12:02:23 +02:00
|
|
|
/** prints option comment with indentation and wrapping.
|
|
|
|
|
|
|
|
The comment column starts at startpos, and has width of width
|
|
|
|
Current cursor position is curpos, returns new cursor position
|
|
|
|
|
|
|
|
@note can print one character beyond width!
|
|
|
|
*/
|
|
|
|
static uint print_comment(const char *comment,
|
|
|
|
int curpos, int startpos, int width)
|
|
|
|
{
|
|
|
|
const char *end= strend(comment);
|
|
|
|
int endpos= startpos + width;
|
|
|
|
|
|
|
|
for (; curpos < startpos; curpos++)
|
|
|
|
putchar(' ');
|
|
|
|
|
|
|
|
if (*comment == '.' || *comment == ',')
|
|
|
|
{
|
|
|
|
putchar(*comment);
|
|
|
|
comment++;
|
|
|
|
curpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (end - comment > endpos - curpos)
|
|
|
|
{
|
|
|
|
const char *line_end;
|
|
|
|
for (line_end= comment + endpos - curpos;
|
|
|
|
line_end > comment && *line_end != ' ';
|
|
|
|
line_end--);
|
|
|
|
for (; comment < line_end; comment++)
|
|
|
|
putchar(*comment);
|
|
|
|
while (*comment == ' ')
|
|
|
|
comment++; /* skip the space, as a newline will take it's place now */
|
|
|
|
putchar('\n');
|
|
|
|
for (curpos= 0; curpos < startpos; curpos++)
|
|
|
|
putchar(' ');
|
|
|
|
}
|
|
|
|
printf("%s", comment);
|
2017-09-28 12:38:02 +02:00
|
|
|
return curpos + (int)(end - comment);
|
2014-06-19 12:02:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-06 16:22:43 +01:00
|
|
|
/*
|
|
|
|
function: my_print_options
|
|
|
|
|
|
|
|
Print help for all options and variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void my_print_help(const struct my_option *options)
|
|
|
|
{
|
|
|
|
uint col, name_space= 22, comment_space= 57;
|
|
|
|
const struct my_option *optp;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("my_print_help");
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (optp= options; optp->name; optp++)
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
2014-06-19 12:02:23 +02:00
|
|
|
const char *typelib_help= 0;
|
2013-11-25 15:49:40 +01:00
|
|
|
if (!optp->comment)
|
|
|
|
continue;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (optp->id && optp->id < 256)
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
2002-05-24 13:06:58 +02:00
|
|
|
printf(" -%c%s", optp->id, strlen(optp->name) ? ", " : " ");
|
2002-02-06 16:22:43 +01:00
|
|
|
col= 6;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
col= 2;
|
|
|
|
}
|
2002-05-24 13:06:58 +02:00
|
|
|
if (strlen(optp->name))
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
printf("--");
|
|
|
|
col+= 2 + print_name(optp);
|
|
|
|
if (optp->arg_type == NO_ARG ||
|
2017-07-21 18:56:41 +02:00
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_BOOL ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_BIT)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
putchar(' ');
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
else if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_ENUM ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_SET ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_FLAGSET )
|
2002-05-24 13:06:58 +02:00
|
|
|
{
|
|
|
|
printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "",
|
|
|
|
optp->arg_type == OPT_ARG ? "]" : "");
|
|
|
|
col+= (optp->arg_type == OPT_ARG) ? 8 : 6;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "",
|
|
|
|
optp->arg_type == OPT_ARG ? "]" : "");
|
|
|
|
col+= (optp->arg_type == OPT_ARG) ? 5 : 3;
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
|
|
|
if (optp->comment && *optp->comment)
|
|
|
|
{
|
2014-06-19 12:02:23 +02:00
|
|
|
uint count;
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2014-06-19 12:02:23 +02:00
|
|
|
if (col > name_space)
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
|
|
|
putchar('\n');
|
2014-06-19 12:02:23 +02:00
|
|
|
col= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
col= print_comment(optp->comment, col, name_space, comment_space);
|
2015-08-10 21:45:11 +02:00
|
|
|
if (optp->var_type & GET_AUTO)
|
|
|
|
{
|
|
|
|
col= print_comment(" (Automatically configured unless set explicitly)",
|
|
|
|
col, name_space, comment_space);
|
|
|
|
}
|
2014-06-19 12:02:23 +02:00
|
|
|
|
|
|
|
switch (optp->var_type & GET_TYPE_MASK) {
|
|
|
|
case GET_ENUM:
|
|
|
|
typelib_help= ". One of: ";
|
|
|
|
count= optp->typelib->count;
|
|
|
|
break;
|
|
|
|
case GET_SET:
|
|
|
|
typelib_help= ". Any combination of: ";
|
|
|
|
count= optp->typelib->count;
|
|
|
|
break;
|
|
|
|
case GET_FLAGSET:
|
|
|
|
typelib_help= ". Takes a comma-separated list of option=value pairs, "
|
|
|
|
"where value is on, off, or default, and options are: ";
|
|
|
|
count= optp->typelib->count - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (typelib_help &&
|
|
|
|
strstr(optp->comment, optp->typelib->type_names[0]) == NULL)
|
|
|
|
{
|
2015-01-31 12:54:07 +01:00
|
|
|
uint i;
|
2014-06-19 12:02:23 +02:00
|
|
|
col= print_comment(typelib_help, col, name_space, comment_space);
|
|
|
|
col= print_comment(optp->typelib->type_names[0], col, name_space, comment_space);
|
|
|
|
for (i= 1; i < count; i++)
|
|
|
|
{
|
|
|
|
col= print_comment(", ", col, name_space, comment_space);
|
|
|
|
col= print_comment(optp->typelib->type_names[i], col, name_space, comment_space);
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
2024-03-12 15:26:29 +01:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_SET)
|
|
|
|
col= print_comment(", or ALL to set all combinations", col, name_space, comment_space);
|
|
|
|
if (optp->deprecation_substitute != NULL)
|
|
|
|
{
|
|
|
|
col= print_comment(". Deprecated, will be removed in a future release.",
|
|
|
|
col, name_space, comment_space);
|
|
|
|
if (!IS_DEPRECATED_NO_REPLACEMENT(optp->deprecation_substitute))
|
|
|
|
{
|
|
|
|
char buf1[NAME_CHAR_LEN + 3];
|
|
|
|
DBUG_ASSERT(strlen(optp->deprecation_substitute) < NAME_CHAR_LEN);
|
|
|
|
strxmov(buf1, "--", optp->deprecation_substitute, NullS);
|
|
|
|
convert_underscore_to_dash(buf1, strlen(buf1));
|
|
|
|
col= print_comment(" Please use ", col, name_space, comment_space);
|
|
|
|
col= print_comment(buf1, col, name_space, comment_space);
|
|
|
|
col= print_comment(" instead.", col, name_space, comment_space);
|
|
|
|
}
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
|
|
|
putchar('\n');
|
2022-07-02 12:20:49 +02:00
|
|
|
if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL ||
|
|
|
|
(optp->var_type & GET_TYPE_MASK) == GET_BIT)
|
2009-11-03 10:22:22 +01:00
|
|
|
{
|
|
|
|
if (optp->def_value != 0)
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
printf("%*s(Defaults to on; use --skip-", name_space, "");
|
|
|
|
print_name(optp);
|
|
|
|
printf(" to disable.)\n");
|
2009-11-03 10:22:22 +01:00
|
|
|
}
|
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
function: my_print_options
|
|
|
|
|
|
|
|
Print variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void my_print_variables(const struct my_option *options)
|
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
uint name_space= 34, length, nr;
|
2009-12-22 10:35:56 +01:00
|
|
|
ulonglong llvalue;
|
2002-02-06 16:22:43 +01:00
|
|
|
char buff[255];
|
|
|
|
const struct my_option *optp;
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_ENTER("my_print_variables");
|
2002-02-06 16:22:43 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (optp= options; optp->name; optp++)
|
|
|
|
{
|
2018-02-06 13:55:58 +01:00
|
|
|
length= (uint)strlen(optp->name)+1;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (length > name_space)
|
|
|
|
name_space= length;
|
|
|
|
}
|
|
|
|
|
2002-05-22 19:45:19 +02:00
|
|
|
printf("\nVariables (--variable-name=value)\n");
|
2009-12-22 10:35:56 +01:00
|
|
|
printf("%-*s%s", name_space, "and boolean options {FALSE|TRUE}",
|
|
|
|
"Value (after reading options)\n");
|
|
|
|
for (length=1; length < 75; length++)
|
|
|
|
putchar(length == name_space ? ' ' : '-');
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
for (optp= options; optp->name; optp++)
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
2019-09-29 14:38:53 +02:00
|
|
|
void *value= optp->var_type & GET_ASK_ADDR ?
|
|
|
|
(*my_getopt_get_addr)("", 0, optp, 0) : optp->value;
|
2003-07-06 18:09:57 +02:00
|
|
|
if (value)
|
2002-02-06 16:22:43 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
length= print_name(optp);
|
2002-02-06 16:22:43 +01:00
|
|
|
for (; length < name_space; length++)
|
|
|
|
putchar(' ');
|
2003-06-27 17:51:39 +02:00
|
|
|
switch ((optp->var_type & GET_TYPE_MASK)) {
|
2007-03-02 17:43:45 +01:00
|
|
|
case GET_SET:
|
|
|
|
if (!(llvalue= *(ulonglong*) value))
|
2009-12-22 10:35:56 +01:00
|
|
|
printf("%s\n", "");
|
2007-03-02 17:43:45 +01:00
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
for (nr= 0; llvalue && nr < optp->typelib->count; nr++, llvalue >>=1)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (llvalue & 1)
|
|
|
|
printf( llvalue > 1 ? "%s," : "%s\n", get_type(optp->typelib, nr));
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-12-22 10:35:56 +01:00
|
|
|
case GET_FLAGSET:
|
|
|
|
llvalue= *(ulonglong*) value;
|
|
|
|
for (nr= 0; llvalue && nr < optp->typelib->count; nr++, llvalue >>=1)
|
|
|
|
{
|
|
|
|
printf("%s%s=", (nr ? "," : ""), get_type(optp->typelib, nr));
|
|
|
|
printf(llvalue & 1 ? "on" : "off");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
break;
|
2007-03-02 17:43:45 +01:00
|
|
|
case GET_ENUM:
|
2010-08-04 14:58:09 +02:00
|
|
|
printf("%s\n", get_type(optp->typelib, *(ulong*) value));
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_STR:
|
|
|
|
case GET_STR_ALLOC: /* fall through */
|
2003-07-06 18:09:57 +02:00
|
|
|
printf("%s\n", *((char**) value) ? *((char**) value) :
|
2002-05-22 19:45:19 +02:00
|
|
|
"(No default value)");
|
|
|
|
break;
|
|
|
|
case GET_BOOL:
|
2003-07-06 18:09:57 +02:00
|
|
|
printf("%s\n", *((my_bool*) value) ? "TRUE" : "FALSE");
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
2017-07-21 18:56:41 +02:00
|
|
|
case GET_BIT:
|
|
|
|
{
|
|
|
|
ulonglong bit= (optp->block_size >= 0 ?
|
|
|
|
optp->block_size :
|
|
|
|
-optp->block_size);
|
|
|
|
my_bool reverse= optp->block_size < 0;
|
|
|
|
printf("%s\n", ((*((ulonglong*) value) & bit) != 0) ^ reverse ?
|
|
|
|
"TRUE" : "FALSE");
|
|
|
|
break;
|
|
|
|
}
|
2002-05-22 19:45:19 +02:00
|
|
|
case GET_INT:
|
2003-07-06 18:09:57 +02:00
|
|
|
printf("%d\n", *((int*) value));
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_UINT:
|
2009-02-15 11:58:34 +01:00
|
|
|
printf("%u\n", *((uint*) value));
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_LONG:
|
2007-02-23 12:13:55 +01:00
|
|
|
printf("%ld\n", *((long*) value));
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_ULONG:
|
2003-07-06 18:09:57 +02:00
|
|
|
printf("%lu\n", *((ulong*) value));
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_LL:
|
2003-07-06 18:09:57 +02:00
|
|
|
printf("%s\n", llstr(*((longlong*) value), buff));
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
|
|
|
case GET_ULL:
|
2010-08-07 14:27:23 +02:00
|
|
|
longlong10_to_str(*((ulonglong*) value), buff, 10);
|
2002-05-22 19:45:19 +02:00
|
|
|
printf("%s\n", buff);
|
|
|
|
break;
|
2007-07-30 10:33:50 +02:00
|
|
|
case GET_DOUBLE:
|
2024-09-11 22:55:14 +02:00
|
|
|
printf("%.10g\n", *(double*) value);
|
2007-07-30 10:33:50 +02:00
|
|
|
break;
|
2009-12-22 10:35:56 +01:00
|
|
|
case GET_NO_ARG:
|
|
|
|
printf("(No default value)\n");
|
|
|
|
break;
|
2004-01-14 03:58:37 +01:00
|
|
|
default:
|
|
|
|
printf("(Disabled)\n");
|
2002-05-22 19:45:19 +02:00
|
|
|
break;
|
2002-05-07 19:35:06 +02:00
|
|
|
}
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-10 20:21:18 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2002-02-06 16:22:43 +01:00
|
|
|
}
|