summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2021-02-05 14:57:46 +0200
committerMonty <monty@mariadb.org>2021-02-08 12:16:29 +0200
commit5d6ad2ad66a677b67f2377d7665d6c140dd93323 (patch)
tree85a54b1a982beb401f04d5bcb621a1166b33b653 /client
parente30a3048dacca5180e8d7b2934d0b1fe44b4f383 (diff)
downloadmariadb-git-5d6ad2ad66a677b67f2377d7665d6c140dd93323.tar.gz
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 *'.
Diffstat (limited to 'client')
-rw-r--r--client/mariadb-conv.cc2
-rw-r--r--client/mysql.cc16
-rw-r--r--client/mysql_plugin.c3
-rw-r--r--client/mysql_upgrade.c11
-rw-r--r--client/mysqladmin.cc13
-rw-r--r--client/mysqlbinlog.cc57
-rw-r--r--client/mysqlcheck.c12
-rw-r--r--client/mysqldump.c16
-rw-r--r--client/mysqlimport.c11
-rw-r--r--client/mysqlshow.c11
-rw-r--r--client/mysqlslap.c11
-rw-r--r--client/mysqltest.cc12
12 files changed, 118 insertions, 57 deletions
diff --git a/client/mariadb-conv.cc b/client/mariadb-conv.cc
index 03018a93dbc..835c6a2abe2 100644
--- a/client/mariadb-conv.cc
+++ b/client/mariadb-conv.cc
@@ -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;
}
diff --git a/client/mysql.cc b/client/mysql.cc
index dcd9dfecef9..f2938d4c824 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -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;
diff --git a/client/mysql_plugin.c b/client/mysql_plugin.c
index eddae6114e6..79b97eaea02 100644
--- a/client/mysql_plugin.c
+++ b/client/mysql_plugin.c
@@ -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':
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 55afdbf9671..e49b0fd0dc0 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -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
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index 1a128e61533..5b59cbed30d 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -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;
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 02bff7c294c..fd31ab6694e 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -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");
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index d7eeec6198b..fb3103a318d 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -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;
diff --git a/client/mysqldump.c b/client/mysqldump.c
index da4ec2756eb..7c363973da2 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -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;
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index 6cb32da2239..99b46ce3c6b 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -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;
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 2b0cae6dc98..a89f4eb1dd2 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -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;
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index 15aae234a94..1109ffbf3c8 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -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;
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 417d3615995..13282153cfb 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -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