1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

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 *'.
This commit is contained in:
Monty
2021-02-05 14:57:46 +02:00
parent e30a3048da
commit 5d6ad2ad66
53 changed files with 300 additions and 165 deletions

View File

@@ -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;
// Skip blanks at the end of key
while (ptr > key && my_isspace(&my_charset_latin1, ptr[-1]))
ptr--;
if (ptr == key)
{
sql_print_error("Bad syntax in rewrite-db: empty FROM db\n");
return 1;
}
key= strmake_root(&glob_root, key, (size_t) (ptr-key));
/* Skipp pre space in value */
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;
if (!*key)
// 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-from!\n");
return 1;
}
// Skip blanks at the end of val
ptr= val;
while (*ptr && !my_isspace(&my_charset_latin1, *ptr))
ptr++;
*ptr= 0;
if (!*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");