Skip to content

Commit 3a498d8

Browse files
committed
Bug#28787273: FIX -WCAST-QUAL COMPILATION WARNINGS [noclose]
Avoid casting away constness using C-style cast. Either use const consistently or explicitly remove const with const_cast. Patch 1. Change-Id: If0345987a9bb349d19622eb501db79bbda10a575
1 parent eff44a6 commit 3a498d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+440
-471
lines changed

client/mysqltest.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -5046,7 +5046,6 @@ static void do_let(struct st_command *command) {
50465046

50475047
static int do_sleep(struct st_command *command, bool real_sleep) {
50485048
int error = 0;
5049-
char *sleep_start, *sleep_end;
50505049
double sleep_val;
50515050
char *p;
50525051
static DYNAMIC_STRING ds_sleep;
@@ -5057,12 +5056,12 @@ static int do_sleep(struct st_command *command, bool real_sleep) {
50575056
sizeof(sleep_args) / sizeof(struct command_arg), ' ');
50585057

50595058
p = ds_sleep.str;
5060-
sleep_end = ds_sleep.str + ds_sleep.length;
5059+
const char *sleep_end = ds_sleep.str + ds_sleep.length;
50615060
while (my_isspace(charset_info, *p)) p++;
50625061
if (!*p)
50635062
die("Missing argument to %.*s", static_cast<int>(command->first_word_len),
50645063
command->query);
5065-
sleep_start = p;
5064+
const char *sleep_start = p;
50665065
/* Check that arg starts with a digit, not handled by my_strtod */
50675066
if (!my_isdigit(charset_info, *sleep_start))
50685067
die("Invalid argument to %.*s \"%s\"",

include/decimal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -55,7 +55,7 @@ struct decimal_t {
5555
};
5656

5757
#ifndef MYSQL_ABI_CHECK
58-
int string2decimal(const char *from, decimal_t *to, char **end);
58+
int string2decimal(const char *from, decimal_t *to, const char **end);
5959
int decimal2string(const decimal_t *from, char *to, int *to_len,
6060
int fixed_precision, int fixed_decimals, char filler);
6161
int decimal2ulonglong(decimal_t *from, ulonglong *to);

include/m_ctype.h

+17-19
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,20 @@ typedef struct MY_CHARSET_HANDLER {
333333

334334
/* String-to-number conversion routines */
335335
long (*strntol)(const CHARSET_INFO *, const char *s, size_t l, int base,
336-
char **e, int *err);
336+
const char **e, int *err);
337337
ulong (*strntoul)(const CHARSET_INFO *, const char *s, size_t l, int base,
338-
char **e, int *err);
338+
const char **e, int *err);
339339
longlong (*strntoll)(const CHARSET_INFO *, const char *s, size_t l, int base,
340-
char **e, int *err);
340+
const char **e, int *err);
341341
ulonglong (*strntoull)(const CHARSET_INFO *, const char *s, size_t l,
342-
int base, char **e, int *err);
343-
double (*strntod)(const CHARSET_INFO *, char *s, size_t l, char **e,
342+
int base, const char **e, int *err);
343+
double (*strntod)(const CHARSET_INFO *, char *s, size_t l, const char **e,
344344
int *err);
345-
longlong (*strtoll10)(const CHARSET_INFO *cs, const char *nptr, char **endptr,
346-
int *error);
345+
longlong (*strtoll10)(const CHARSET_INFO *cs, const char *nptr,
346+
const char **endptr, int *error);
347347
ulonglong (*strntoull10rnd)(const CHARSET_INFO *cs, const char *str,
348-
size_t length, int unsigned_fl, char **endptr,
349-
int *error);
348+
size_t length, int unsigned_fl,
349+
const char **endptr, int *error);
350350
size_t (*scan)(const CHARSET_INFO *, const char *b, const char *e, int sq);
351351
} MY_CHARSET_HANDLER;
352352

@@ -474,28 +474,28 @@ size_t my_snprintf_8bit(const CHARSET_INFO *, char *to, size_t n,
474474
MY_ATTRIBUTE((format(printf, 4, 5)));
475475

476476
long my_strntol_8bit(const CHARSET_INFO *, const char *s, size_t l, int base,
477-
char **e, int *err);
477+
const char **e, int *err);
478478
ulong my_strntoul_8bit(const CHARSET_INFO *, const char *s, size_t l, int base,
479-
char **e, int *err);
479+
const char **e, int *err);
480480
longlong my_strntoll_8bit(const CHARSET_INFO *, const char *s, size_t l,
481-
int base, char **e, int *err);
481+
int base, const char **e, int *err);
482482
ulonglong my_strntoull_8bit(const CHARSET_INFO *, const char *s, size_t l,
483-
int base, char **e, int *err);
484-
double my_strntod_8bit(const CHARSET_INFO *, char *s, size_t l, char **e,
483+
int base, const char **e, int *err);
484+
double my_strntod_8bit(const CHARSET_INFO *, char *s, size_t l, const char **e,
485485
int *err);
486486
size_t my_long10_to_str_8bit(const CHARSET_INFO *, char *to, size_t l,
487487
int radix, long int val);
488488
size_t my_longlong10_to_str_8bit(const CHARSET_INFO *, char *to, size_t l,
489489
int radix, longlong val);
490490

491491
longlong my_strtoll10_8bit(const CHARSET_INFO *cs, const char *nptr,
492-
char **endptr, int *error);
492+
const char **endptr, int *error);
493493
longlong my_strtoll10_ucs2(const CHARSET_INFO *cs, const char *nptr,
494494
char **endptr, int *error);
495495

496496
ulonglong my_strntoull10rnd_8bit(const CHARSET_INFO *cs, const char *str,
497-
size_t length, int unsigned_fl, char **endptr,
498-
int *error);
497+
size_t length, int unsigned_fl,
498+
const char **endptr, int *error);
499499
ulonglong my_strntoull10rnd_ucs2(const CHARSET_INFO *cs, const char *str,
500500
size_t length, int unsigned_fl, char **endptr,
501501
int *error);
@@ -605,8 +605,6 @@ int my_wildcmp_unicode(const CHARSET_INFO *cs, const char *str,
605605

606606
extern bool my_parse_charset_xml(MY_CHARSET_LOADER *loader, const char *buf,
607607
size_t buflen);
608-
extern char *my_strchr(const CHARSET_INFO *cs, const char *str, const char *end,
609-
char c);
610608
extern size_t my_strcspn(const CHARSET_INFO *cs, const char *str,
611609
const char *end, const char *reject,
612610
size_t reject_length);

include/m_string.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extern char _dig_vec_lower[];
6464
/* Prototypes for string functions */
6565

6666
extern char *strmake(char *dst, const char *src, size_t length);
67-
extern char *strcont(const char *src, const char *set);
67+
extern char *strcont(char *src, const char *set);
6868
extern char *strxmov(char *dst, const char *src, ...);
6969
extern char *strxnmov(char *dst, size_t len, const char *src, ...);
7070

@@ -239,7 +239,7 @@ static inline int is_prefix(const char *s, const char *t) {
239239
/* Conversion routines */
240240
typedef enum { MY_GCVT_ARG_FLOAT, MY_GCVT_ARG_DOUBLE } my_gcvt_arg_type;
241241

242-
double my_strtod(const char *str, char **end, int *error);
242+
double my_strtod(const char *str, const char **end, int *error);
243243
double my_atof(const char *nptr);
244244
size_t my_fcvt(double x, int precision, char *to, bool *error);
245245
size_t my_fcvt_compact(double x, char *to, bool *error);
@@ -277,9 +277,9 @@ extern char *int2str(long val, char *dst, int radix, int upcase);
277277
C_MODE_START
278278
extern char *int10_to_str(long val, char *dst, int radix);
279279
C_MODE_END
280-
extern char *str2int(const char *src, int radix, long lower, long upper,
281-
long *val);
282-
longlong my_strtoll10(const char *nptr, char **endptr, int *error);
280+
extern const char *str2int(const char *src, int radix, long lower, long upper,
281+
long *val);
282+
longlong my_strtoll10(const char *nptr, const char **endptr, int *error);
283283
#if SIZEOF_LONG == SIZEOF_LONG_LONG
284284
#define ll2str(A, B, C, D) int2str((A), (B), (C), (D))
285285
#define longlong10_to_str(A, B, C) int10_to_str((A), (B), (C))
@@ -307,7 +307,6 @@ static inline char *ullstr(longlong value, char *buff) {
307307
}
308308

309309
#define STRING_WITH_LEN(X) (X), ((sizeof(X) - 1))
310-
#define USTRING_WITH_LEN(X) ((uchar *)X), ((sizeof(X) - 1))
311310
#define C_STRING_WITH_LEN(X) ((char *)(X)), ((sizeof(X) - 1))
312311

313312
/**

libbinlogevents/include/uuid.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -65,7 +65,9 @@ struct Uuid {
6565
memcpy(bytes, data, BYTE_LENGTH);
6666
}
6767
/// Copies the given UUID object to this UUID.
68-
void copy_from(const Uuid &data) { copy_from((unsigned char *)data.bytes); }
68+
void copy_from(const Uuid &data) {
69+
copy_from(pointer_cast<const unsigned char *>(data.bytes));
70+
}
6971
/// Copies the given UUID object to this UUID.
7072
void copy_to(unsigned char *data) const { memcpy(data, bytes, BYTE_LENGTH); }
7173
/// Returns true if this UUID is equal the given UUID.

libbinlogevents/src/statement_events.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ Query_event::Query_event(const char *buf, const Format_description_event *fde,
282282
*/
283283
if (binary_log_debug::debug_query_mts_corrupt_db_names) {
284284
if (mts_accessed_dbs == 2) {
285-
const char *pos = READER_CALL(ptr);
285+
char *pos = const_cast<char *>(READER_CALL(ptr));
286286
BAPI_ASSERT(pos[sizeof("d?") - 1] == 0);
287-
((char *)pos)[sizeof("d?") - 1] = 'a';
287+
pos[sizeof("d?") - 1] = 'a';
288288
is_corruption_injected = true;
289289
}
290290
}

libmysql/libmysql.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,7 @@ static void read_binary_date(MYSQL_TIME *tm, uchar **pos) {
29492949
static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
29502950
size_t length) {
29512951
uchar *buffer = pointer_cast<uchar *>(param->buffer);
2952-
char *endptr = value + length;
2952+
const char *endptr = value + length;
29532953

29542954
/*
29552955
This function should support all target buffer types: the rest

mysys_ssl/my_getopt.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ my_error_reporter my_getopt_error_reporter = &my_message_local;
6262
static bool getopt_compare_strings(const char *, const char *, uint);
6363
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
6464
static ulonglong getopt_ull(char *, const struct my_option *, int *);
65-
static double getopt_double(char *arg, const struct my_option *optp, int *err);
65+
static double getopt_double(const char *arg, const struct my_option *optp,
66+
int *err);
6667
static void init_variables(const struct my_option *, init_func_p);
6768
static void init_one_value(const struct my_option *, void *, longlong);
6869
static void fini_one_value(const struct my_option *, void *, longlong);
@@ -1236,10 +1237,11 @@ double getopt_double_limit_value(double num, const struct my_option *optp,
12361237
EXIT_ARGUMENT_INVALID. Otherwise err is not touched
12371238
*/
12381239

1239-
static double getopt_double(char *arg, const struct my_option *optp, int *err) {
1240+
static double getopt_double(const char *arg, const struct my_option *optp,
1241+
int *err) {
12401242
double num;
12411243
int error;
1242-
char *end = arg + 1000; /* Big enough as *arg is \0 terminated */
1244+
const char *end = arg + 1000; /* Big enough as *arg is \0 terminated */
12431245
num = my_strtod(arg, &end, &error);
12441246
if (end[0] != 0 || error) {
12451247
my_getopt_error_reporter(ERROR_LEVEL, EE_INVALID_DECIMAL_VALUE_FOR_OPTION,

sql/field.cc

+14-13
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ type_conversion_status Field_num::get_int(const CHARSET_INFO *cs,
15241524
longlong *rnd, ulonglong unsigned_max,
15251525
longlong signed_min,
15261526
longlong signed_max) {
1527-
char *end;
1527+
const char *end;
15281528
int error;
15291529

15301530
*rnd = (longlong)cs->cset->strntoull10rnd(cs, from, len, unsigned_flag, &end,
@@ -2648,7 +2648,7 @@ type_conversion_status Field_decimal::store(longlong nr, bool unsigned_val) {
26482648
double Field_decimal::val_real() {
26492649
ASSERT_COLUMN_MARKED_FOR_READ;
26502650
int not_used;
2651-
char *end_not_used;
2651+
const char *end_not_used;
26522652
return my_strntod(&my_charset_bin, (char *)ptr, field_length, &end_not_used,
26532653
&not_used);
26542654
}
@@ -3904,7 +3904,7 @@ type_conversion_status Field_longlong::store(const char *from, size_t len,
39043904
ASSERT_COLUMN_MARKED_FOR_WRITE;
39053905
int conv_err = 0;
39063906
type_conversion_status error = TYPE_OK;
3907-
char *end;
3907+
const char *end;
39083908
ulonglong tmp;
39093909

39103910
tmp = cs->cset->strntoull10rnd(cs, from, len, unsigned_flag, &end, &conv_err);
@@ -4130,7 +4130,7 @@ type_conversion_status Field_float::store(const char *from, size_t len,
41304130
const CHARSET_INFO *cs) {
41314131
int conv_error;
41324132
type_conversion_status err = TYPE_OK;
4133-
char *end;
4133+
const char *end;
41344134
double nr = my_strntod(cs, (char *)from, len, &end, &conv_error);
41354135
if (conv_error || (!len || ((uint)(end - from) != len &&
41364136
table->in_use->check_for_truncated_fields))) {
@@ -4309,7 +4309,7 @@ type_conversion_status Field_double::store(const char *from, size_t len,
43094309
const CHARSET_INFO *cs) {
43104310
int conv_error;
43114311
type_conversion_status error = TYPE_OK;
4312-
char *end;
4312+
const char *end;
43134313
double nr = my_strntod(cs, (char *)from, len, &end, &conv_error);
43144314
if (conv_error != 0 || len == 0 ||
43154315
(((uint)(end - from) != len &&
@@ -5582,7 +5582,7 @@ bool Field_timef::get_time(MYSQL_TIME *ltime) {
55825582
type_conversion_status Field_year::store(const char *from, size_t len,
55835583
const CHARSET_INFO *cs) {
55845584
ASSERT_COLUMN_MARKED_FOR_WRITE;
5585-
char *end;
5585+
const char *end;
55865586
int conv_error;
55875587
type_conversion_status ret = TYPE_OK;
55885588
longlong nr = cs->cset->strntoull10rnd(cs, from, len, 0, &end, &conv_error);
@@ -6269,7 +6269,7 @@ uint32 Field_longstr::max_data_length() const {
62696269
double Field_string::val_real() {
62706270
ASSERT_COLUMN_MARKED_FOR_READ;
62716271
int error;
6272-
char *end;
6272+
const char *end;
62736273
const CHARSET_INFO *cs = charset();
62746274
double result;
62756275

@@ -6290,7 +6290,7 @@ double Field_string::val_real() {
62906290
longlong Field_string::val_int() {
62916291
ASSERT_COLUMN_MARKED_FOR_READ;
62926292
int error;
6293-
char *end;
6293+
const char *end;
62946294
const CHARSET_INFO *cs = charset();
62956295
longlong result;
62966296

@@ -6675,7 +6675,7 @@ type_conversion_status Field_varstring::store(longlong nr, bool unsigned_val) {
66756675
double Field_varstring::val_real() {
66766676
ASSERT_COLUMN_MARKED_FOR_READ;
66776677
int error;
6678-
char *end;
6678+
const char *end;
66796679
double result;
66806680
const CHARSET_INFO *cs = charset();
66816681

@@ -6695,7 +6695,7 @@ double Field_varstring::val_real() {
66956695
longlong Field_varstring::val_int() {
66966696
ASSERT_COLUMN_MARKED_FOR_READ;
66976697
int error;
6698-
char *end;
6698+
const char *end;
66996699
const CHARSET_INFO *cs = charset();
67006700

67016701
uint length = length_bytes == 1 ? (uint)*ptr : uint2korr(ptr);
@@ -7184,7 +7184,8 @@ type_conversion_status Field_blob::store(longlong nr, bool unsigned_val) {
71847184
double Field_blob::val_real() {
71857185
ASSERT_COLUMN_MARKED_FOR_READ;
71867186
int not_used;
7187-
char *end_not_used, *blob;
7187+
const char *end_not_used;
7188+
char *blob;
71887189
uint32 length;
71897190
const CHARSET_INFO *cs;
71907191

@@ -8186,7 +8187,7 @@ type_conversion_status Field_enum::store(const char *from, size_t length,
81868187
if (length < 6) // Can't be more than 99999 enums
81878188
{
81888189
/* This is for reading numbers with LOAD DATA INFILE */
8189-
char *end;
8190+
const char *end;
81908191
tmp = (uint)my_strntoul(cs, from, length, 10, &end, &err);
81918192
if (err || end != from + length || tmp > typelib->count) {
81928193
tmp = 0;
@@ -8397,7 +8398,7 @@ type_conversion_status Field_set::store(const char *from, size_t length,
83978398
&not_used2, &got_warning);
83988399
if (!tmp && length && length < 22) {
83998400
/* This is for reading numbers with LOAD DATA INFILE */
8400-
char *end;
8401+
const char *end;
84018402
tmp = my_strntoull(cs, from, length, 10, &end, &err);
84028403
if (err || end != from + length ||
84038404
(typelib->count < 64 && tmp >= (1ULL << typelib->count))) {

sql/gstream.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -71,7 +71,7 @@ bool Gis_read_stream::get_next_word(LEX_STRING *res) {
7171

7272
/* Read a floating point number. */
7373
bool Gis_read_stream::get_next_number(double *d) {
74-
char *endptr;
74+
const char *endptr;
7575
int err;
7676

7777
skip_space();

0 commit comments

Comments
 (0)