Commit 5d6ad2ad authored by Monty's avatar Monty

Added 'const' to arguments in get_one_option and find_typeset()

One should not change the program arguments!
This change also reduces warnings from the icc compiler.

Almost all changes are just syntax changes (adding const to
'get_one_option function' declarations).

Other changes:
- Added a few cast of 'argument' from 'const char*' to 'char *'. This
  was mainly in calls to 'external' functions we don't have control of.
- Ensure that all reset of 'password command line argument' are similar.
  (In almost all cases it was just adding a comment and a cast)
- In mysqlbinlog.cc and mysqld.cc there was a few cases that changed
  the command line argument. These places where changed to instead allocate
  the option in a MEM_ROOT to avoid changing the argument. Some of this
  code was changed to ensure that different programs did parsing the
  same way. Added a test case for the changes in mysqlbinlog.cc
- Changed a few variables that took their value from command line options
  from 'char *' to 'const char *'.
parent e30a3048
......@@ -76,7 +76,7 @@ static struct my_option long_options[] =
my_bool
get_one_option(const struct my_option *opt,
char *value, const char *filename)
const char *value, const char *filename)
{
return 0;
}
......
......@@ -218,7 +218,7 @@ static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool)
/* The names of functions that actually do the manipulation. */
static int get_options(int argc,char **argv);
extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
char *argument);
const char *argument);
static int com_quit(String *str,char*),
com_go(String *str,char*), com_ego(String *str,char*),
com_print(String *str,char*),
......@@ -1715,7 +1715,7 @@ static void usage(int version)
my_bool
get_one_option(const struct my_option *opt, char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *)
{
switch(opt->id) {
case OPT_CHARSETS_DIR:
......@@ -1816,7 +1816,8 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
status.add_to_history= 0;
if (!status.line_buff)
ignore_errors= 0; // do it for the first -e only
if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
if (!(status.line_buff= batch_readline_command(status.line_buff,
(char*) argument)))
return 1;
break;
case 'o':
......@@ -1830,10 +1831,15 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
argument= (char*) ""; // Don't require password
if (argument)
{
char *start= argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; // Destroy argument
while (*argument)
*(char*)argument++= 'x'; // Destroy argument
if (*start)
start[1]=0 ;
tty_password= 0;
......
......@@ -475,7 +475,8 @@ static void print_default_values(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
switch(opt->id) {
case 'n':
......
......@@ -270,7 +270,7 @@ static void add_one_option_cnf_file(DYNAMIC_STRING *ds,
}
static my_bool
get_one_option(const struct my_option *opt, char *argument,
get_one_option(const struct my_option *opt, const char *argument,
const char *filename __attribute__((unused)))
{
my_bool add_option= TRUE;
......@@ -301,10 +301,17 @@ get_one_option(const struct my_option *opt, char *argument,
add_option= FALSE;
if (argument)
{
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
/* Add password to ds_args before overwriting the arg with x's */
add_one_option_cnf_file(&ds_args, opt, argument);
while (*argument)
*argument++= 'x'; /* Destroy argument */
*(char*)argument++= 'x'; /* Destroy argument */
if (*start)
start[1]= 0;
tty_password= 0;
}
else
......
......@@ -69,7 +69,7 @@ static uint ex_var_count, max_var_length, max_val_length;
static void print_version(void);
static void usage(void);
extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
char *argument);
const char *argument);
static my_bool sql_connect(MYSQL *mysql, uint wait);
static int execute_commands(MYSQL *mysql,int argc, char **argv);
static char **mask_password(int argc, char ***argv);
......@@ -241,7 +241,7 @@ static const char *load_default_groups[]=
0 };
my_bool
get_one_option(const struct my_option *opt, char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *)
{
switch(opt->id) {
case 'c':
......@@ -252,10 +252,15 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
argument= (char*) ""; // Don't require password
if (argument)
{
char *start=argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
tty_password= 0;
......
......@@ -96,6 +96,7 @@ static FILE *result_file;
static char *result_file_name= 0;
static const char *output_prefix= "";
static char **defaults_argv= 0;
static MEM_ROOT glob_root;
#ifndef DBUG_OFF
static const char *default_dbug_option = "d:t:o,/tmp/mariadb-binlog.trace";
......@@ -1889,6 +1890,7 @@ static void cleanup()
my_free(const_cast<char*>(dirname_for_local_load));
my_free(start_datetime_str);
my_free(stop_datetime_str);
free_root(&glob_root, MYF(0));
delete binlog_filter;
delete glob_description_event;
......@@ -1957,7 +1959,7 @@ static my_time_t convert_str_to_timestamp(const char* str)
extern "C" my_bool
get_one_option(const struct my_option *opt, char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *)
{
bool tty_password=0;
switch (opt->id) {
......@@ -1981,10 +1983,15 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
argument= (char*) ""; // Don't require password
if (argument)
{
/*
One should not really change the argument, but we make an
exception for passwords
*/
my_free(pass);
char *start=argument;
char *start= (char*) argument;
pass= my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*)argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
}
......@@ -2035,46 +2042,46 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
case OPT_REWRITE_DB: // db_from->db_to
{
/* See also handling of OPT_REPLICATE_REWRITE_DB in sql/mysqld.cc */
char* ptr;
char* key= argument; // db-from
char* val; // db-to
const char* ptr;
const char* key= argument; // db-from
const char* val; // db-to
// Where key begins
// Skipp pre-space in key
while (*key && my_isspace(&my_charset_latin1, *key))
key++;
// Where val begins
if (!(ptr= strstr(argument, "->")))
if (!(ptr= strstr(key, "->")))
{
sql_print_error("Bad syntax in rewrite-db: missing '->'!\n");
sql_print_error("Bad syntax in rewrite-db: missing '->'\n");
return 1;
}
val= ptr + 2;
while (*val && my_isspace(&my_charset_latin1, *val))
val++;
// Write \0 and skip blanks at the end of key
*ptr-- = 0;
while (my_isspace(&my_charset_latin1, *ptr) && ptr > argument)
*ptr-- = 0;
// Skip blanks at the end of key
while (ptr > key && my_isspace(&my_charset_latin1, ptr[-1]))
ptr--;
if (!*key)
if (ptr == key)
{
sql_print_error("Bad syntax in rewrite-db: empty db-from!\n");
sql_print_error("Bad syntax in rewrite-db: empty FROM db\n");
return 1;
}
key= strmake_root(&glob_root, key, (size_t) (ptr-key));
// Skip blanks at the end of val
ptr= val;
while (*ptr && !my_isspace(&my_charset_latin1, *ptr))
ptr++;
*ptr= 0;
/* Skipp pre space in value */
while (*val && my_isspace(&my_charset_latin1, *val))
val++;
if (!*val)
// Value ends with \0 or space
for (ptr= val; *ptr && !my_isspace(&my_charset_latin1, *ptr) ; ptr++)
{}
if (ptr == val)
{
sql_print_error("Bad syntax in rewrite-db: empty db-to!\n");
sql_print_error("Bad syntax in rewrite-db: empty TO db\n");
return 1;
}
val= strmake_root(&glob_root, val, (size_t) (ptr-val));
binlog_filter->add_db_rewrite(key, val);
break;
......@@ -3045,6 +3052,8 @@ int main(int argc, char** argv)
load_defaults_or_exit("my", load_groups, &argc, &argv);
defaults_argv= argv;
init_alloc_root(PSI_NOT_INSTRUMENTED, &glob_root, 1024, 0, MYF(0));
if (!(binlog_filter= new Rpl_filter))
{
error("Failed to create Rpl_filter");
......
......@@ -285,7 +285,8 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
int orig_what_to_do= what_to_do;
DBUG_ENTER("get_one_option");
......@@ -324,10 +325,15 @@ get_one_option(const struct my_option *opt,
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start = argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password = my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1] = 0; /* Cut length of argument */
tty_password= 0;
......
......@@ -144,9 +144,9 @@ static char *opt_password=0,*current_user=0,
*current_host=0,*path=0,*fields_terminated=0,
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
*where=0, *order_by=0,
*opt_compatible_mode_str= 0,
*err_ptr= 0,
*log_error_file= NULL;
static const char *opt_compatible_mode_str= 0;
static char **defaults_argv= 0;
static char compatible_mode_normal_str[255];
/* Server supports character_set_results session variable? */
......@@ -279,7 +279,7 @@ static struct my_option my_long_options[] =
"no_table_options, no_field_options. One can use several modes separated "
"by commas. Note: Requires MariaDB server version 4.1.0 or higher. "
"This option is ignored with earlier server versions.",
&opt_compatible_mode_str, &opt_compatible_mode_str, 0,
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"compact", OPT_COMPACT,
"Give less verbose output (useful for debugging). Disables structure "
......@@ -849,7 +849,8 @@ uchar* get_table_key(const char *entry, size_t *length,
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
switch (opt->id) {
case 'p':
......@@ -857,10 +858,15 @@ get_one_option(const struct my_option *opt,
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start=argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
tty_password= 0;
......
......@@ -221,7 +221,7 @@ file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
static my_bool
get_one_option(const struct my_option *opt, char *argument,
get_one_option(const struct my_option *opt, const char *argument,
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......@@ -230,10 +230,15 @@ get_one_option(const struct my_option *opt, char *argument,
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start=argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
tty_password= 0;
......
......@@ -289,7 +289,7 @@ are shown.");
static my_bool
get_one_option(const struct my_option *opt, char *argument,
get_one_option(const struct my_option *opt, const char *argument,
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......@@ -301,10 +301,15 @@ get_one_option(const struct my_option *opt, char *argument,
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start=argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
tty_password= 0;
......
......@@ -726,7 +726,7 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt, char *argument,
get_one_option(const struct my_option *opt, const char *argument,
const char *filename __attribute__((unused)))
{
DBUG_ENTER("get_one_option");
......@@ -739,10 +739,15 @@ get_one_option(const struct my_option *opt, char *argument,
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start= argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]= 0; /* Cut length of argument */
tty_password= 0;
......
......@@ -97,7 +97,8 @@ static int setenv(const char *name, const char *value, int overwrite);
C_MODE_START
static sig_handler signal_handler(int sig);
static my_bool get_one_option(const struct my_option *, char *, const char *);
static my_bool get_one_option(const struct my_option *, const char *,
const char *);
C_MODE_END
enum {
......@@ -7141,7 +7142,7 @@ void read_embedded_server_arguments(const char *name)
static my_bool
get_one_option(const struct my_option *opt, char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *)
{
switch(opt->id) {
case '#':
......@@ -7189,9 +7190,14 @@ get_one_option(const struct my_option *opt, char *argument, const char *)
argument= const_cast<char*>(""); // Don't require password
if (argument)
{
/*
One should not really change the argument, but we make an
exception for passwords
*/
my_free(opt_pass);
opt_pass= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*)argument++= 'x'; /* Destroy argument */
tty_password= 0;
}
else
......
......@@ -1140,7 +1140,7 @@ static void print_version(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__ ((unused)),
const char *argument __attribute__ ((unused)),
const char *filename __attribute__ ((unused)))
{
DBUG_ENTER("get_one_option");
......
......@@ -1332,7 +1332,7 @@ static void usage(void)
extern "C" my_bool
innochecksum_get_one_option(
const struct my_option *opt,
char *argument MY_ATTRIBUTE((unused)),
const char *argument MY_ATTRIBUTE((unused)),
const char *)
{
switch (opt->id) {
......
......@@ -88,7 +88,7 @@ char *opt_ibx_incremental_history_name = NULL;
char *opt_ibx_incremental_history_uuid = NULL;
char *opt_ibx_user = NULL;
char *opt_ibx_password = NULL;
const char *opt_ibx_password = NULL;
char *opt_ibx_host = NULL;
char *opt_ibx_defaults_group = NULL;
char *opt_ibx_socket = NULL;
......@@ -731,7 +731,7 @@ indicates an error.\n");
static
my_bool
ibx_get_one_option(const struct my_option *opt,
char *argument, const char *)
const char *argument, const char *)
{
switch(opt->id) {
case '?':
......
......@@ -90,7 +90,7 @@ static int get_options(int *argc, char ***argv);
static int mode_create(int argc, char **argv);
static int mode_extract(int n_threads, int argc, char **argv);
static my_bool get_one_option(const struct my_option *opt,
char *argument, const char *filename);
const char *argument, const char *filename);
int
main(int argc, char **argv)
......@@ -138,7 +138,8 @@ get_options(int *argc, char ***argv)
int ho_error;
if ((ho_error= handle_options(argc, argv, my_long_options,
get_one_option))) {
get_one_option)))
{
exit(EXIT_FAILURE);
}
......@@ -191,7 +192,7 @@ set_run_mode(run_mode_t mode)
static
my_bool
get_one_option(const struct my_option *opt, char *, const char *)
get_one_option(const struct my_option *opt, const char *, const char *)
{
switch (opt->id) {
case 'c':
......
......@@ -311,7 +311,7 @@ char *opt_incremental_history_name;
char *opt_incremental_history_uuid;
char *opt_user;
char *opt_password;
const char *opt_password;
char *opt_host;
char *opt_defaults_group;
char *opt_socket;
......@@ -1861,7 +1861,7 @@ check_if_param_set(const char *param)
my_bool
xb_get_one_option(const struct my_option *opt,
char *argument, const char *)
const char *argument, const char *)
{
switch(opt->id) {
case 'h':
......@@ -6348,9 +6348,10 @@ void handle_options(int argc, char **argv, char ***argv_server,
if (opt_password)
{
char *argument= opt_password;
char *start= argument;
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, opt_password, MYF(MY_FAE));
char *argument= (char*) opt_password;
char *start= (char*) opt_password;
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, opt_password,
MYF(MY_FAE));
while (*argument)
*argument++= 'x'; // Destroy argument
if (*start)
......
......@@ -144,7 +144,7 @@ extern char *opt_incremental_history_name;
extern char *opt_incremental_history_uuid;
extern char *opt_user;
extern char *opt_password;
extern const char *opt_password;
extern char *opt_host;
extern char *opt_defaults_group;
extern char *opt_socket;
......
......@@ -105,7 +105,7 @@ static void usage()
static my_bool
get_one_option(const struct my_option *opt __attribute__((unused)),
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename)
{
switch (opt->id) {
......
......@@ -45,7 +45,7 @@ static struct my_option my_long_options[] =
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -97,7 +97,7 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch (opt->id) {
......
......@@ -112,7 +112,7 @@ void local_exit(int error)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -72,7 +72,7 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch (opt->id) {
......
......@@ -89,7 +89,7 @@ struct my_option
void *app_type; /**< To be used by an application */
};
typedef my_bool (*my_get_one_option)(const struct my_option *, char *, const char *);
typedef my_bool (*my_get_one_option)(const struct my_option *, const char *, const char *);
/**
Used to retrieve a reference to the object (variable) that holds the value
......
......@@ -270,7 +270,8 @@ typedef struct st_typelib {
const char **type_names;
unsigned int *type_lengths;
} TYPELIB;
extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
extern my_ulonglong find_typeset(const char *x, TYPELIB *typelib,
int *error_position);
extern int find_type_with_warning(const char *x, TYPELIB *typelib,
const char *option);
extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags);
......
......@@ -27,7 +27,8 @@ typedef struct st_typelib { /* Different types saved here */
unsigned int *type_lengths;
} TYPELIB;
extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
extern my_ulonglong find_typeset(const char *x, TYPELIB *typelib,
int *error_position);
extern int find_type_with_warning(const char *x, TYPELIB *typelib,
const char *option);
#define FIND_TYPE_BASIC 0
......
......@@ -1257,3 +1257,21 @@ ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
mysqlbinlog Ver VER for OS at ARCH
#
# Test --rewrite-db
#
RESET MASTER;
CREATE TABLE t1 (a int);
INSERT INTO t1 values(1);
DROP TABLE t1;
FLUSH LOGS;
ERROR: Bad syntax in rewrite-db: missing '->'
ERROR: Bad syntax in rewrite-db: empty TO db
ERROR: Bad syntax in rewrite-db: empty TO db
ERROR: Bad syntax in rewrite-db: empty FROM db
ERROR: Bad syntax in rewrite-db: empty FROM db
......@@ -130,6 +130,7 @@ select "--- reading stdin --" as "";
# postion is constant to correspond to an event in pre-recorded binlog
--let $binlog_start_pos=79
--exec $MYSQL_BINLOG --short-form --start-position=$binlog_start_pos - < $MYSQL_TEST_DIR/std_data/trunc_binlog.000001
drop table t1,t2;
#
......@@ -595,3 +596,30 @@ eval SET GLOBAL SERVER_ID = $old_server_id;
#
replace_regex /.*mysqlbinlog(\.exe)? Ver .* for .* at [-_a-zA-Z0-9]+/mysqlbinlog Ver VER for OS at ARCH/;
exec $MYSQL_BINLOG --version;
--echo #
--echo # Test --rewrite-db
--echo #
RESET MASTER;
CREATE TABLE t1 (a int);
INSERT INTO t1 values(1);
DROP TABLE t1;
FLUSH LOGS;
--error 1
--exec $MYSQL_BINLOG --rewrite-db=a --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
--error 1
--exec $MYSQL_BINLOG --rewrite-db="a->" --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
--error 1
--exec $MYSQL_BINLOG --rewrite-db="a-> " --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
--error 1
--exec $MYSQL_BINLOG --rewrite-db="->b" --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
--error 1
--exec $MYSQL_BINLOG --rewrite-db=" ->" --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
--exec $MYSQL_BINLOG --rewrite-db=" test -> foo " --short-form $MYSQLD_DATADIR/master-bin.000001 > /dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn
......@@ -182,11 +182,11 @@ const char *get_type(TYPELIB *typelib, uint nr)
a integer representation of the supplied string
*/
my_ulonglong find_typeset(char *x, TYPELIB *lib, int *err)
my_ulonglong find_typeset(const char *x, TYPELIB *lib, int *err)
{
my_ulonglong result;
int find;
char *i;
const char *i;
DBUG_ENTER("find_set");
DBUG_PRINT("enter",("x: '%s' lib: %p", x, lib));
......
......@@ -96,7 +96,7 @@ static struct my_option my_long_options[]=
static my_bool
get_one_option(const struct my_option *opt, char *, const char *)
get_one_option(const struct my_option *opt, const char *, const char *)
{
DBUG_ENTER("get_one_option");
switch (opt->id) {
......
......@@ -78,7 +78,7 @@ static struct my_option my_long_options[]=
static my_bool
get_one_option(const struct my_option *opt, char *, const char *)
get_one_option(const struct my_option *opt, const char *, const char *)
{
DBUG_ENTER("get_one_option");
switch (opt->id) {
......
......@@ -329,7 +329,7 @@ static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
static my_bool opt_short_log_format= 0, opt_silent_startup= 0;
ulong max_used_connections;
static char *mysqld_user, *mysqld_chroot;
static const char *mysqld_user, *mysqld_chroot;
static char *default_character_set_name;
static char *character_set_filesystem_name;
static char *lc_messages;
......@@ -372,6 +372,8 @@ uint volatile global_disable_checkpoint;
#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
ulong slow_start_timeout;
#endif
static MEM_ROOT startup_root;
/**
@brief 'grant_option' is used to indicate if privileges needs
to be checked, in which case the lock, LOCK_grant, is used
......@@ -1484,7 +1486,8 @@ static int mysql_init_variables(void);
static int get_options(int *argc_ptr, char ***argv_ptr);
static bool add_terminator(DYNAMIC_ARRAY *options);
static bool add_many_options(DYNAMIC_ARRAY *, my_option *, size_t);
extern "C" my_bool mysqld_get_one_option(const struct my_option *, char *, const char *);
extern "C" my_bool mysqld_get_one_option(const struct my_option *, const char *,
const char *);
static int init_thread_environment();
static char *get_relative_path(const char *path);
static int fix_paths(void);
......@@ -2028,6 +2031,7 @@ static void clean_up(bool print_message)
thread_scheduler= 0;
mysql_library_end();
finish_client_errs();
free_root(&startup_root, MYF(0));
cleanup_errmsgs();
free_error_messages();
/* Tell main we are ready */
......@@ -3591,6 +3595,7 @@ static int init_early_variables()
set_current_thd(0);
set_malloc_size_cb(my_malloc_size_cb_func);
global_status_var.global_memory_used= 0;
init_alloc_root(PSI_NOT_INSTRUMENTED, &startup_root, 1024, 0, MYF(0));
return 0;
}
......@@ -7890,7 +7895,7 @@ static int mysql_init_variables(void)
}
my_bool
mysqld_get_one_option(const struct my_option *opt, char *argument,
mysqld_get_one_option(const struct my_option *opt, const char *argument,
const char *filename)
{
if (opt->app_type)
......@@ -8067,31 +8072,43 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
case (int)OPT_REPLICATE_REWRITE_DB:
{
/* See also OPT_REWRITE_DB handling in client/mysqlbinlog.cc */
char* key = argument,*p, *val;
const char* key= argument, *ptr, *val;
// Skipp pre-space in key
while (*key && my_isspace(mysqld_charset, *key))
key++;
if (!(p= strstr(argument, "->")))
// Where val begins
if (!(ptr= strstr(key, "->")))
{
sql_print_error("Bad syntax in replicate-rewrite-db - missing '->'!");
sql_print_error("Bad syntax in replicate-rewrite-db: missing '->'");
return 1;
}
val= p--;
while (my_isspace(mysqld_charset, *p) && p > argument)
*p-- = 0;
/* Db name can be one char also */
if (p == argument && my_isspace(mysqld_charset, *p))
val= ptr+2;
// Skip blanks at the end of key
while (ptr > key && my_isspace(mysqld_charset, ptr[-1]))
ptr--;
if (ptr == key)
{
sql_print_error("Bad syntax in replicate-rewrite-db - empty FROM db!");
sql_print_error("Bad syntax in replicate-rewrite-db - empty FROM db");
return 1;
}
*val= 0;
val+= 2;
key= strmake_root(&startup_root, key, (size_t) (ptr-key));
/* Skipp pre space in value */
while (*val && my_isspace(mysqld_charset, *val))
val++;
if (!*val)
// Value ends with \0 or space
for (ptr= val; *ptr && !my_isspace(&my_charset_latin1, *ptr) ; ptr++)
{}
if (ptr == val)
{
sql_print_error("Bad syntax in replicate-rewrite-db - empty TO db!");
sql_print_error("Bad syntax in replicate-rewrite-db - empty TO db");
return 1;
}
val= strmake_root(&startup_root, val, (size_t) (ptr-val));
cur_rpl_filter->add_db_rewrite(key, val);
break;
......@@ -8118,7 +8135,7 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
{
if (cur_rpl_filter->add_do_table(argument))
{
sql_print_error("Could not add do table rule '%s'!", argument);
sql_print_error("Could not add do table rule '%s'", argument);
return 1;
}
break;
......@@ -8127,7 +8144,7 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
{
if (cur_rpl_filter->add_wild_do_table(argument))
{
sql_print_error("Could not add do table rule '%s'!", argument);
sql_print_error("Could not add do table rule '%s'", argument);
return 1;
}
break;
......@@ -8136,7 +8153,7 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
{
if (cur_rpl_filter->add_wild_ignore_table(argument))
{
sql_print_error("Could not add ignore table rule '%s'!", argument);
sql_print_error("Could not add ignore table rule '%s'", argument);
return 1;
}
break;
......@@ -8145,7 +8162,7 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
{
if (cur_rpl_filter->add_ignore_table(argument))
{
sql_print_error("Could not add ignore table rule '%s'!", argument);
sql_print_error("Could not add ignore table rule '%s'", argument);
return 1;
}
break;
......@@ -8239,10 +8256,14 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#ifndef EMBEDDED_LIBRARY
/* Parse instrument name and value from argument string */
char* name = argument,*p, *val;
const char *name= argument, *ptr, *val;
/* Trim leading spaces from instrument name */
while (*name && my_isspace(mysqld_charset, *name))
name++;
/* Assignment required */
if (!(p= strchr(argument, '=')))
if (!(ptr= strchr(name, '=')))
{
my_getopt_error_reporter(WARNING_LEVEL,
"Missing value for performance_schema_instrument "
......@@ -8251,54 +8272,43 @@ mysqld_get_one_option(const struct my_option *opt, char *argument,
}
/* Option value */
val= p + 1;
if (!*val)
{
my_getopt_error_reporter(WARNING_LEVEL,
"Missing value for performance_schema_instrument "
"'%s'", argument);
return 0;
}
/* Trim leading spaces from instrument name */
while (*name && my_isspace(mysqld_charset, *name))
name++;
val= ptr + 1;
/* Trim trailing spaces and slashes from instrument name */
while (p > argument && (my_isspace(mysqld_charset, p[-1]) || p[-1] == '/'))
p--;
*p= 0;
if (!*name)
while (ptr > name && (my_isspace(mysqld_charset, ptr[-1]) ||
ptr[-1] == '/'))
ptr--;
if (ptr == name)
{
my_getopt_error_reporter(WARNING_LEVEL,
"Invalid instrument name for "
"performance_schema_instrument '%s'", argument);
return 0;
"performance_schema_instrument '%s'", name);
return 0;
}
name= strmake_root(&startup_root, name, (size_t) (ptr - name));
/* Trim leading spaces from option value */
while (*val && my_isspace(mysqld_charset, *val))
val++;
/* Trim trailing spaces from option value */
if ((p= my_strchr(mysqld_charset, val, val+strlen(val), ' ')) != NULL)
*p= 0;
if (!*val)
/* Find end of value */
for (ptr= val; *ptr && !my_isspace(mysqld_charset, *ptr) ; ptr++)
{}
if (ptr == val)
{
my_getopt_error_reporter(WARNING_LEVEL,
"Invalid value for performance_schema_instrument "
"'%s'", argument);
"No value for performance_schema_instrument "
"'%s'", name);
return 0;
}
val= strmake_root(&startup_root, val, (size_t) (ptr - val));
/* Add instrument name and value to array of configuration options */
if (add_pfs_instr_to_array(name, val))
{
my_getopt_error_reporter(WARNING_LEVEL,
"Invalid value for performance_schema_instrument "
"'%s'", argument);
"'%s'", name);
return 0;
}
#endif /* EMBEDDED_LIBRARY */
......@@ -8465,7 +8475,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
/* Skip unknown options so that they may be processed later by plugins */
my_getopt_skip_unknown= TRUE;
if ((ho_error= handle_options(argc_ptr, argv_ptr, (my_option*)(all_options.buffer),
if ((ho_error= handle_options(argc_ptr, argv_ptr,
(my_option*) (all_options.buffer),
mysqld_get_one_option)))
return ho_error;
......
......@@ -4043,8 +4043,10 @@ static my_option *construct_help_options(MEM_ROOT *mem_root,
DBUG_RETURN(opts);
}
extern "C" my_bool mark_changed(const struct my_option *, char *, const char *);
my_bool mark_changed(const struct my_option *opt, char *, const char *filename)
extern "C" my_bool mark_changed(const struct my_option *, const char *,
const char *);
my_bool mark_changed(const struct my_option *opt, const char *,
const char *filename)
{
if (opt->app_type)
{
......
......@@ -618,8 +618,7 @@ db_dirs_hash_get_key(const uchar *data, size_t *len_ret,
@retval FALSE success
*/
bool
push_ignored_db_dir(char *path)
bool push_ignored_db_dir(const char *path)
{
LEX_CSTRING *new_elt;
char *new_elt_buffer;
......
......@@ -253,7 +253,7 @@ bool ignore_db_dirs_init();
void ignore_db_dirs_free();
void ignore_db_dirs_reset();
bool ignore_db_dirs_process_additions();
bool push_ignored_db_dir(char *path);
bool push_ignored_db_dir(const char *path);
extern char *opt_ignore_db_dirs;
#endif /* SQL_SHOW_H */
......@@ -2656,7 +2656,8 @@ static struct my_option my_long_options[] =
C_MODE_START
static my_bool get_one_option(const struct my_option *, char *, const char *);
static my_bool get_one_option(const struct my_option *, const char *,
const char *);
C_MODE_END
static void print_version(void)
......@@ -2678,7 +2679,7 @@ static void print_usage(void)
static my_bool
get_one_option(const struct my_option *opt, char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *)
{
switch(opt->id) {
case '#':
......
......@@ -639,7 +639,8 @@ TYPELIB maria_stats_method_typelib= {
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
switch (opt->id) {
#ifdef __NETWARE__
......
......@@ -88,7 +88,7 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch (opt->id) {
......
......@@ -21,7 +21,8 @@
static void usage();
static void complain(int val);
static my_bool get_one_option(const struct my_option *, char *, const char*);
static my_bool get_one_option(const struct my_option *, const char *,
const char*);
static int count=0, stats=0, dump=0, lstats=0;
static my_bool verbose;
......@@ -233,7 +234,7 @@ int main(int argc,char *argv[])
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -381,7 +381,8 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
uint length;
......
......@@ -343,7 +343,8 @@ static uchar* my_hash_get_string(const uchar *record, size_t *length,
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
switch (opt->id) {
case '?':
......
......@@ -138,7 +138,7 @@ ATTRIBUTE_NORETURN static void my_exit(int exit_code)
extern "C" my_bool get_one_option(const struct my_option *opt
__attribute__((unused)),
char *argument, const char *filename)
const char *argument, const char *filename)
{
switch (opt->id) {
case 'V':
......
......@@ -645,7 +645,7 @@ static struct my_option my_long_options[] =
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -813,7 +813,7 @@ static struct my_option my_long_options[] =
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -580,7 +580,7 @@ static void version(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -190,7 +190,7 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch (opt->id) {
......
......@@ -589,7 +589,7 @@ static struct my_option my_long_options[] =
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -22,7 +22,8 @@
static void usage();
static void complain(int val);
static my_bool get_one_option(const struct my_option *, char *, const char *);
static my_bool get_one_option(const struct my_option *, const char *,
const char *);
static int count=0, stats=0, dump=0, lstats=0;
static my_bool verbose;
......@@ -229,7 +230,7 @@ int main(int argc,char *argv[])
static my_bool
get_one_option(const struct my_option *opt,
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
switch(opt->id) {
......
......@@ -471,7 +471,7 @@ TYPELIB myisam_stats_method_typelib= {
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument, const char *filename __attribute__((unused)))
{
switch (opt->id) {
case 'a':
......
......@@ -317,7 +317,8 @@ static void usage(void)
static my_bool
get_one_option(const struct my_option *opt,
char *argument, const char *filename __attribute__((unused)))
const char *argument,
const char *filename __attribute__((unused)))
{
uint length;
......
......@@ -335,7 +335,7 @@ add_query(const char *q)
static my_bool
handle_option(const struct my_option *opt, char *arg,
handle_option(const struct my_option *opt, const char *arg,
const char *filename __attribute__((unused)))
{
switch (opt->id)
......
......@@ -1273,7 +1273,7 @@ static struct my_tests_st *get_my_tests(); /* To be defined in main .c file */
static struct my_tests_st *my_testlist= 0;
static my_bool
get_one_option(const struct my_option *opt, char *argument,
get_one_option(const struct my_option *opt, const char *argument,
const char *filename __attribute__((unused)))
{
switch (opt->id) {
......@@ -1286,10 +1286,15 @@ get_one_option(const struct my_option *opt, char *argument,
case 'p':
if (argument)
{
char *start=argument;
/*
One should not really change the argument, but we make an
exception for passwords
*/
char *start= (char*) argument;
my_free(opt_password);
opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0;
}
......
......@@ -61,7 +61,7 @@ static struct my_option mopts_options[]=
};
my_bool dummy_get_one_option(const struct my_option *opt __attribute__((unused)),
char *argument __attribute__((unused)),
const char *argument __attribute__((unused)),
const char *filename __attribute__((unused)))
{
return FALSE;
......@@ -235,7 +235,7 @@ static struct my_option auto_options[]=
my_bool auto_get_one_option(const struct my_option *opt,
char *argument,
const char *argument,
const char *filename __attribute__((unused)))
{
if (argument == autoset_my_option)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment