Skip to content

Commit 6aec21f

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 3. Change-Id: Ifb539c1fe7d9c2f4ab901527890bf5df464d36f4
1 parent 480714f commit 6aec21f

34 files changed

+173
-189
lines changed

dbug/dbug.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ void _db_dump_(uint _line_, const char *keyword, const unsigned char *memory,
13811381

13821382
pos = 0;
13831383
while (length-- > 0) {
1384-
uint tmp = *((unsigned char *)memory++);
1384+
uint tmp = *(memory++);
13851385
if ((pos += 3) >= 80) {
13861386
fputc('\n', cs->stack->out_file);
13871387
pos = 3;

include/my_sys.h

+57-35
Original file line numberDiff line numberDiff line change
@@ -495,42 +495,64 @@ extern my_error_reporter my_charset_error_reporter;
495495
extern PSI_file_key key_file_io_cache;
496496

497497
/* Test if buffer is inited */
498-
#define my_b_clear(info) (info)->buffer = 0
499-
#define my_b_inited(info) (info)->buffer
500-
#define my_b_EOF INT_MIN
501-
502-
#define my_b_read(info, Buffer, Count) \
503-
((info)->read_pos + (Count) <= (info)->read_end \
504-
? (memcpy(Buffer, (info)->read_pos, (size_t)(Count)), \
505-
((info)->read_pos += (Count)), 0) \
506-
: (*(info)->read_function)((info), Buffer, Count))
507-
508-
#define my_b_write(info, Buffer, Count) \
509-
((info)->write_pos + (Count) <= (info)->write_end \
510-
? (memcpy((info)->write_pos, (Buffer), (size_t)(Count)), \
511-
((info)->write_pos += (Count)), 0) \
512-
: (*(info)->write_function)((info), (uchar *)(Buffer), (Count)))
513-
514-
#define my_b_get(info) \
515-
((info)->read_pos != (info)->read_end \
516-
? ((info)->read_pos++, (int)(uchar)(info)->read_pos[-1]) \
517-
: _my_b_get(info))
518-
519-
#define my_b_tell(info) \
520-
((info)->pos_in_file + (size_t)(*(info)->current_pos - (info)->request_pos))
521-
522-
#define my_b_get_buffer_start(info) (info)->request_pos
523-
#define my_b_get_bytes_in_buffer(info) \
524-
(char *)(info)->read_end - (char *)my_b_get_buffer_start(info)
525-
#define my_b_get_pos_in_file(info) (info)->pos_in_file
498+
inline void my_b_clear(IO_CACHE *info) { info->buffer = nullptr; }
499+
500+
inline bool my_b_inited(const IO_CACHE *info) {
501+
return info->buffer != nullptr;
502+
}
503+
504+
constexpr int my_b_EOF = INT_MIN;
505+
506+
inline int my_b_read(IO_CACHE *info, uchar *buffer, size_t count) {
507+
if (info->read_pos + count <= info->read_end) {
508+
memcpy(buffer, info->read_pos, count);
509+
info->read_pos += count;
510+
return 0;
511+
}
512+
return (*info->read_function)(info, buffer, count);
513+
}
514+
515+
inline int my_b_write(IO_CACHE *info, const uchar *buffer, size_t count) {
516+
if (info->write_pos + count <= info->write_end) {
517+
memcpy(info->write_pos, buffer, count);
518+
info->write_pos += count;
519+
return 0;
520+
}
521+
return (*info->write_function)(info, buffer, count);
522+
}
523+
524+
extern int _my_b_get(IO_CACHE *info);
525+
526+
inline int my_b_get(IO_CACHE *info) {
527+
if (info->read_pos != info->read_end) {
528+
info->read_pos++;
529+
return info->read_pos[-1];
530+
}
531+
return _my_b_get(info);
532+
}
533+
534+
inline my_off_t my_b_tell(const IO_CACHE *info) {
535+
return info->pos_in_file + *info->current_pos - info->request_pos;
536+
}
537+
538+
inline uchar *my_b_get_buffer_start(const IO_CACHE *info) {
539+
return info->request_pos;
540+
}
541+
542+
inline size_t my_b_get_bytes_in_buffer(const IO_CACHE *info) {
543+
return info->read_end - my_b_get_buffer_start(info);
544+
}
545+
546+
inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info) {
547+
return info->pos_in_file;
548+
}
526549

527550
/* tell write offset in the SEQ_APPEND cache */
528551
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
529-
my_off_t my_b_append_tell(IO_CACHE *info);
530-
my_off_t my_b_safe_tell(IO_CACHE *info); /* picks the correct tell() */
531552

532-
#define my_b_bytes_in_cache(info) \
533-
(size_t)(*(info)->current_end - *(info)->current_pos)
553+
inline size_t my_b_bytes_in_cache(const IO_CACHE *info) {
554+
return *info->current_end - *info->current_pos;
555+
}
534556

535557
typedef uint32 ha_checksum;
536558

@@ -669,7 +691,7 @@ void my_message_local_stderr(enum loglevel, uint ecode, va_list args);
669691
extern void my_message_local(enum loglevel ll, uint ecode, ...);
670692
extern bool my_init(void);
671693
extern void my_end(int infoflag);
672-
extern char *my_filename(File fd);
694+
extern const char *my_filename(File fd);
673695
extern MY_MODE get_file_perm(ulong perm_flags);
674696
extern bool my_chmod(const char *filename, ulong perm_flags, myf my_flags);
675697

@@ -690,7 +712,8 @@ extern int test_if_hard_path(const char *dir_name);
690712
extern bool has_path(const char *name);
691713
extern char *convert_dirname(char *to, const char *from, const char *from_end);
692714
extern void to_unix_path(char *name);
693-
extern char *fn_ext(const char *name);
715+
extern char *fn_ext(char *name);
716+
extern const char *fn_ext(const char *name);
694717
extern char *fn_same(char *toname, const char *name, int flag);
695718
extern char *fn_format(char *to, const char *name, const char *dir,
696719
const char *form, uint flag);
@@ -729,7 +752,6 @@ extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
729752
extern void remove_io_thread(IO_CACHE *info);
730753
extern int _my_b_seq_read(IO_CACHE *info, uchar *Buffer, size_t Count);
731754
extern int _my_b_net_read(IO_CACHE *info, uchar *Buffer, size_t Count);
732-
extern int _my_b_get(IO_CACHE *info);
733755
extern int _my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count);
734756
extern int my_b_append(IO_CACHE *info, const uchar *Buffer, size_t Count);
735757
extern int my_b_safe_write(IO_CACHE *info, const uchar *Buffer, size_t Count);

include/typelib.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ extern TYPELIB sql_protocol_typelib;
6262
my_ulonglong find_set_from_flags(const TYPELIB *lib, size_t default_name,
6363
my_ulonglong cur_set, my_ulonglong default_set,
6464
const char *str, unsigned int length,
65-
char **err_pos, unsigned int *err_len);
65+
const char **err_pos, unsigned int *err_len);
6666

6767
#endif /* _typelib_h */

mysys/mf_fn_ext.cc

+13-14
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,19 @@
5555
points at the end ASCII(0) of the filename.
5656
*/
5757

58-
char *fn_ext(const char *name) {
59-
const char *pos, *gpos;
60-
DBUG_ENTER("fn_ext");
61-
DBUG_PRINT("mfunkt", ("name: '%s'", name));
62-
58+
const char *fn_ext(const char *name) {
6359
#if defined(FN_DEVCHAR) || defined(_WIN32)
64-
{
65-
char buff[FN_REFLEN];
66-
size_t res_length;
67-
gpos = name + dirname_part(buff, (char *)name, &res_length);
68-
}
60+
char buff[FN_REFLEN];
61+
size_t res_length;
62+
const char *gpos = name + dirname_part(buff, name, &res_length);
6963
#else
70-
if (!(gpos = strrchr(name, FN_LIBCHAR))) gpos = name;
64+
const char *gpos = strrchr(name, FN_LIBCHAR);
65+
if (gpos == nullptr) gpos = name;
7166
#endif
72-
pos = strrchr(gpos, FN_EXTCHAR);
73-
DBUG_RETURN((char *)(pos ? pos : strend(gpos)));
74-
} /* fn_ext */
67+
const char *pos = strrchr(gpos, FN_EXTCHAR);
68+
return pos ? pos : strend(gpos);
69+
}
70+
71+
char *fn_ext(char *name) {
72+
return const_cast<char *>(fn_ext(static_cast<const char *>(name)));
73+
}

mysys/mf_iocache2.cc

+5-56
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "my_sys.h"
4545
#include "mysql/psi/mysql_file.h"
4646
#include "mysql/psi/mysql_mutex.h"
47+
#include "template_utils.h"
4748

4849
/*
4950
Copy contents of an IO_CACHE to a file.
@@ -86,60 +87,6 @@ int my_b_copy_to_file(IO_CACHE *cache, FILE *file) {
8687
DBUG_RETURN(0);
8788
}
8889

89-
my_off_t my_b_append_tell(IO_CACHE *info) {
90-
/*
91-
Sometimes we want to make sure that the variable is not put into
92-
a register in debugging mode so we can see its value in the core
93-
*/
94-
#ifndef DBUG_OFF
95-
#define dbug_volatile volatile
96-
#else
97-
#define dbug_volatile
98-
#endif
99-
100-
/*
101-
Prevent optimizer from putting res in a register when debugging
102-
we need this to be able to see the value of res when the assert fails
103-
*/
104-
dbug_volatile my_off_t res;
105-
106-
/*
107-
We need to lock the append buffer mutex to keep flush_io_cache()
108-
from messing with the variables that we need in order to provide the
109-
answer to the question.
110-
*/
111-
mysql_mutex_lock(&info->append_buffer_lock);
112-
113-
#ifndef DBUG_OFF
114-
/*
115-
Make sure EOF is where we think it is. Note that we cannot just use
116-
mysql_file_tell() because we have a reader thread that could have left the
117-
file offset in a non-EOF location
118-
*/
119-
{
120-
volatile my_off_t save_pos;
121-
save_pos = mysql_file_tell(info->file, MYF(0));
122-
mysql_file_seek(info->file, (my_off_t)0, MY_SEEK_END, MYF(0));
123-
/*
124-
Save the value of mysql_file_tell in res so we can see it when studying
125-
coredump
126-
*/
127-
DBUG_ASSERT(info->end_of_file -
128-
(info->append_read_pos - info->write_buffer) ==
129-
(res = mysql_file_tell(info->file, MYF(0))));
130-
mysql_file_seek(info->file, save_pos, MY_SEEK_SET, MYF(0));
131-
}
132-
#endif
133-
res = info->end_of_file + (info->write_pos - info->append_read_pos);
134-
mysql_mutex_unlock(&info->append_buffer_lock);
135-
return res;
136-
}
137-
138-
my_off_t my_b_safe_tell(IO_CACHE *info) {
139-
if (unlikely(info->type == SEQ_READ_APPEND)) return my_b_append_tell(info);
140-
return my_b_tell(info);
141-
}
142-
14390
/*
14491
Make next read happen at the given position
14592
For write cache, make next write happen at the given position
@@ -436,7 +383,8 @@ size_t my_b_vprintf(IO_CACHE *info, const char *fmt, va_list args) {
436383
memset(buffz, '0', minimum_width - length2);
437384
else
438385
memset(buffz, ' ', minimum_width - length2);
439-
if (my_b_write(info, buffz, minimum_width - length2)) {
386+
if (my_b_write(info, pointer_cast<uchar *>(buffz),
387+
minimum_width - length2)) {
440388
goto err;
441389
}
442390
}
@@ -469,7 +417,8 @@ size_t my_b_vprintf(IO_CACHE *info, const char *fmt, va_list args) {
469417
if (my_b_write(info, (uchar *)buff, length2)) goto err;
470418
} else {
471419
/* %% or unknown code */
472-
if (my_b_write(info, (uchar *)backtrack, (size_t)(fmt - backtrack)))
420+
if (my_b_write(info, pointer_cast<const uchar *>(backtrack),
421+
fmt - backtrack))
473422
goto err;
474423
out_length += fmt - backtrack;
475424
}

mysys/mf_keycaches.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2003, 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,
@@ -200,7 +200,7 @@ static bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
200200
goto end;
201201
}
202202
entry->key = (char *)(entry + 1);
203-
memcpy((char *)entry->key, (char *)key, length);
203+
memcpy(entry->key, key, length);
204204
entry->length = length;
205205
entry->data = data;
206206
/* Link entry to list */

mysys/mf_pack.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ static char *expand_tilde(char **path);
7575
*/
7676

7777
size_t cleanup_dirname(char *to, const char *from) {
78-
size_t length;
7978
char *pos;
80-
char *from_ptr;
79+
const char *from_ptr;
8180
char *start;
8281
char parent[5], /* for "FN_PARENTDIR" */
8382
buff[FN_REFLEN + 1], *end_parentdir;
@@ -88,17 +87,20 @@ size_t cleanup_dirname(char *to, const char *from) {
8887
DBUG_PRINT("enter", ("from: '%s'", from));
8988

9089
start = buff;
91-
from_ptr = (char *)from;
90+
from_ptr = from;
9291
#ifdef FN_DEVCHAR
93-
if ((pos = strrchr(from_ptr, FN_DEVCHAR)) != 0) { /* Skip device part */
94-
length = (size_t)(pos - from_ptr) + 1;
95-
start = my_stpnmov(buff, from_ptr, length);
96-
from_ptr += length;
92+
{
93+
const char *dev_pos = strrchr(from_ptr, FN_DEVCHAR);
94+
if (dev_pos != nullptr) { /* Skip device part */
95+
size_t length = (dev_pos - from_ptr) + 1;
96+
start = my_stpnmov(buff, from_ptr, length);
97+
from_ptr += length;
98+
}
9799
}
98100
#endif
99101

100102
parent[0] = FN_LIBCHAR;
101-
length = (size_t)(my_stpcpy(parent + 1, FN_PARENTDIR) - parent);
103+
size_t length = my_stpcpy(parent + 1, FN_PARENTDIR) - parent;
102104
const char *end = start + FN_REFLEN;
103105
for (pos = start; pos < end && ((*pos = *from_ptr++) != 0); pos++) {
104106
#ifdef _WIN32

mysys/mf_path.cc

+5-4
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,
@@ -59,7 +59,8 @@ static char *find_file_in_path(char *to, const char *name);
5959
my_path puts result in to and returns to */
6060

6161
char *my_path(char *to, const char *progname, const char *own_pathname_part) {
62-
char *start, *end, *prog;
62+
char *start, *prog;
63+
const char *end;
6364
size_t to_length;
6465
DBUG_ENTER("my_path");
6566

@@ -78,9 +79,9 @@ char *my_path(char *to, const char *progname, const char *own_pathname_part) {
7879
if ((end = getenv("MY_BASEDIR_VERSION")) == 0 &&
7980
(end = getenv("MY_BASEDIR")) == 0) {
8081
#ifdef DEFAULT_BASEDIR
81-
end = (char *)DEFAULT_BASEDIR;
82+
end = DEFAULT_BASEDIR;
8283
#else
83-
end = (char *)"/my/";
84+
end = "/my/";
8485
#endif
8586
}
8687
(void)intern_filename(to, end);

mysys/my_compress.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ uchar *my_compress_alloc(const uchar *packet, size_t *len, size_t *complen) {
8080
return 0; /* Not enough memory */
8181

8282
tmp_complen = (uint)*complen;
83-
res = compress((Bytef *)compbuf, &tmp_complen, (Bytef *)packet, (uLong)*len);
83+
res = compress(compbuf, &tmp_complen, packet, static_cast<uLong>(*len));
8484
*complen = tmp_complen;
8585

8686
if (res != Z_OK) {
@@ -127,8 +127,7 @@ bool my_uncompress(uchar *packet, size_t len, size_t *complen) {
127127
if (!compbuf) DBUG_RETURN(1); /* Not enough memory */
128128

129129
tmp_complen = (uint)*complen;
130-
error =
131-
uncompress((Bytef *)compbuf, &tmp_complen, (Bytef *)packet, (uLong)len);
130+
error = uncompress(compbuf, &tmp_complen, packet, (uLong)len);
132131
*complen = tmp_complen;
133132
if (error != Z_OK) { /* Probably wrong packet */
134133
DBUG_PRINT("error", ("Can't uncompress packet, error: %d", error));

mysys/my_copy.cc

+3-3
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,
@@ -89,7 +89,7 @@ int my_copy(const char *from, const char *to, myf MyFlags) {
8989
memset(&new_stat_buff, 0, sizeof(MY_STAT));
9090
DBUG_ASSERT(!(MyFlags & (MY_FNABP | MY_NABP))); /* for my_read/my_write */
9191
if (MyFlags & MY_HOLD_ORIGINAL_MODES) /* Copy stat if possible */
92-
new_file_stat = my_stat((char *)to, &new_stat_buff, MYF(0)) != nullptr;
92+
new_file_stat = my_stat(to, &new_stat_buff, MYF(0)) != nullptr;
9393

9494
if ((from_file = my_open(from, O_RDONLY, MyFlags)) >= 0) {
9595
if (!my_stat(from, &stat_buff, MyFlags)) {
@@ -153,7 +153,7 @@ int my_copy(const char *from, const char *to, myf MyFlags) {
153153
struct utimbuf timep;
154154
timep.actime = stat_buff.st_atime;
155155
timep.modtime = stat_buff.st_mtime;
156-
(void)utime((char *)to, &timep); /* last accessed and modified times */
156+
(void)utime(to, &timep); /* last accessed and modified times */
157157
}
158158

159159
DBUG_RETURN(0);

0 commit comments

Comments
 (0)