Skip to content

Commit c5a5708

Browse files
committed
Bug#18259286: REMOVE LINT_INIT/UNINIT_VAR
This patch removes the LINT_INIT/UNINIT_VAR and replaces their usage with explicit initialization to 0/0.0/NULL.
1 parent 2623aab commit c5a5708

Some content is hidden

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

73 files changed

+170
-249
lines changed

BUILD/SETUP.sh

+2-6
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,11 @@ fi
138138

139139
# Set flags for various build configurations.
140140
# Used in -valgrind builds
141-
# Override -DFORCE_INIT_OF_VARS from debug_cflags. It enables the macro
142-
# LINT_INIT(), which is only useful for silencing spurious warnings
143-
# of static analysis tools. We want LINT_INIT() to be a no-op in Valgrind.
144-
valgrind_flags="-UFORCE_INIT_OF_VARS "
145-
valgrind_flags="$valgrind_flags -DMYSQL_SERVER_SUFFIX=-valgrind-max"
141+
valgrind_flags="-DMYSQL_SERVER_SUFFIX=-valgrind-max"
146142
valgrind_configs="--with-valgrind"
147143
#
148144
# Used in -debug builds
149-
debug_cflags="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS "
145+
debug_cflags="-DEXTRA_DEBUG "
150146
debug_cflags="$debug_cflags -DSAFE_MUTEX"
151147
error_inject="--with-error-inject "
152148
#

client/mysql.cc

+3-7
Original file line numberDiff line numberDiff line change
@@ -3345,8 +3345,6 @@ static int com_server_help(String *buffer __attribute__((unused)),
33453345
char last_char= 0;
33463346

33473347
int num_name= 0, num_cat= 0;
3348-
LINT_INIT(num_name);
3349-
LINT_INIT(num_cat);
33503348

33513349
if (num_fields == 2)
33523350
{
@@ -3486,7 +3484,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
34863484
}
34873485

34883486
/* Remove garbage for nicer messages */
3489-
LINT_INIT(buff[0]);
3487+
buff[0]= 0;
34903488
remove_cntrl(*buffer);
34913489

34923490
if (buffer->is_empty())
@@ -5039,8 +5037,7 @@ com_status(String *buffer __attribute__((unused)),
50395037
const char *status_str;
50405038
char buff[40];
50415039
ulonglong id;
5042-
MYSQL_RES *result;
5043-
LINT_INIT(result);
5040+
MYSQL_RES *result= NULL;
50445041

50455042
if (mysql_real_query_for_lazy(
50465043
C_STRING_WITH_LEN("select DATABASE(), USER() limit 1")))
@@ -5658,8 +5655,7 @@ static void init_username()
56585655
my_free(full_username);
56595656
my_free(part_username);
56605657

5661-
MYSQL_RES *result;
5662-
LINT_INIT(result);
5658+
MYSQL_RES *result= NULL;
56635659
if (!mysql_query(&mysql,"select USER()") &&
56645660
(result=mysql_use_result(&mysql)))
56655661
{

client/mysqlcheck.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,10 @@ static char *fix_table_name(char *dest, char *src)
536536

537537
static int process_all_tables_in_db(char *database)
538538
{
539-
MYSQL_RES *res;
539+
MYSQL_RES *res= NULL;
540540
MYSQL_ROW row;
541541
uint num_columns;
542542

543-
LINT_INIT(res);
544543
if (use_db(database))
545544
return 1;
546545
if ((mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") &&

client/mysqlshow.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
690690
int len;
691691
MYSQL_RES *result;
692692
MYSQL_ROW row;
693-
ulong UNINIT_VAR(rows);
693+
ulong rows= 0;
694694

695695
if (mysql_select_db(mysql,db))
696696
{

client/mysqltest.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -2460,12 +2460,11 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
24602460
{
24612461
char *end = (char*)((query_end && *query_end) ?
24622462
*query_end : query + strlen(query));
2463-
MYSQL_RES *res;
2463+
MYSQL_RES *res= NULL;
24642464
MYSQL_ROW row;
24652465
MYSQL* mysql = &cur_con->mysql;
24662466
DYNAMIC_STRING ds_query;
24672467
DBUG_ENTER("var_query_set");
2468-
LINT_INIT(res);
24692468

24702469
/* Only white space or ) allowed past ending ` */
24712470
while (end > query && *end != '`')
@@ -2706,7 +2705,7 @@ void var_set_query_get_value(struct st_command *command, VAR *var)
27062705
{
27072706
long row_no;
27082707
int col_no= -1;
2709-
MYSQL_RES* res;
2708+
MYSQL_RES* res= NULL;
27102709
MYSQL* mysql= &cur_con->mysql;
27112710

27122711
static DYNAMIC_STRING ds_query;
@@ -2719,7 +2718,6 @@ void var_set_query_get_value(struct st_command *command, VAR *var)
27192718
};
27202719

27212720
DBUG_ENTER("var_set_query_get_value");
2722-
LINT_INIT(res);
27232721

27242722
strip_parentheses(command);
27252723
DBUG_PRINT("info", ("query: %s", command->query));
@@ -4341,7 +4339,7 @@ void do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
43414339
MYSQL* mysql = &cur_con->mysql;
43424340
for (;;)
43434341
{
4344-
MYSQL_RES *UNINIT_VAR(res);
4342+
MYSQL_RES *res= NULL;
43454343
MYSQL_ROW row;
43464344
int done;
43474345

@@ -6155,7 +6153,7 @@ my_bool end_of_query(int c)
61556153

61566154
int read_line(char *buf, int size)
61576155
{
6158-
char c, UNINIT_VAR(last_quote), last_char= 0;
6156+
char c, last_quote= 0, last_char= 0;
61596157
char *p= buf, *buf_end= buf + size - 1;
61606158
int skip_char= 0;
61616159
my_bool have_slash= FALSE;

include/my_global.h

-27
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,6 @@ extern "C" int madvise(void *addr, size_t len, int behav);
263263
#define SIGNAL_HANDLER_RESET_ON_DELIVERY
264264
#endif
265265

266-
/*
267-
Deprecated workaround for false-positive uninitialized variables
268-
warnings. Those should be silenced using tool-specific heuristics.
269-
270-
Enabled by default for g++ due to the bug referenced below.
271-
*/
272-
#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \
273-
(defined(__GNUC__) && defined(__cplusplus))
274-
#define LINT_INIT(var) var= 0
275-
#else
276-
#define LINT_INIT(var)
277-
#endif
278-
279266
#ifndef SO_EXT
280267
#ifdef _WIN32
281268
#define SO_EXT ".dll"
@@ -286,20 +273,6 @@ extern "C" int madvise(void *addr, size_t len, int behav);
286273
#endif
287274
#endif
288275

289-
/*
290-
Suppress uninitialized variable warning without generating code.
291-
292-
The _cplusplus is a temporary workaround for C++ code pending a fix
293-
for a g++ bug (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772).
294-
*/
295-
#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \
296-
defined(__cplusplus) || !defined(__GNUC__)
297-
#define UNINIT_VAR(x) x= 0
298-
#else
299-
/* GCC specific self-initialization which inhibits the warning. */
300-
#define UNINIT_VAR(x) x= x
301-
#endif
302-
303276
#if !defined(HAVE_UINT)
304277
#undef HAVE_UINT
305278
#define HAVE_UINT

libmysql/libmysql.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,11 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
844844
MYSQL_RES * STDCALL
845845
mysql_list_processes(MYSQL *mysql)
846846
{
847-
MYSQL_DATA *fields;
847+
MYSQL_DATA *fields= NULL;
848848
uint field_count;
849849
uchar *pos;
850850
DBUG_ENTER("mysql_list_processes");
851851

852-
LINT_INIT(fields);
853852
if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
854853
DBUG_RETURN(0);
855854
free_old_query(mysql);
@@ -1185,7 +1184,7 @@ myodbc_remove_escape(MYSQL *mysql,char *name)
11851184
{
11861185
char *to;
11871186
my_bool use_mb_flag=use_mb(mysql->charset);
1188-
char *UNINIT_VAR(end);
1187+
char *end= NULL;
11891188
if (use_mb_flag)
11901189
for (end=name; *end ; end++) ;
11911190

mysys/hash.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ my_bool my_hash_insert(HASH *info, const uchar *record)
383383
int flag;
384384
size_t idx,halfbuff,first_index;
385385
my_hash_value_type hash_nr;
386-
uchar *UNINIT_VAR(ptr_to_rec),*UNINIT_VAR(ptr_to_rec2);
387-
HASH_LINK *data,*empty,*UNINIT_VAR(gpos),*UNINIT_VAR(gpos2),*pos;
386+
uchar *ptr_to_rec= NULL, *ptr_to_rec2= NULL;
387+
HASH_LINK *data, *empty, *gpos= NULL, *gpos2= NULL, *pos;
388388

389389
if (HASH_UNIQUE & info->flags)
390390
{

mysys/mf_keycache.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -3906,11 +3906,11 @@ static int flush_key_blocks_int(KEY_CACHE *keycache,
39063906
if (!(block->status & (BLOCK_IN_EVICTION | BLOCK_IN_SWITCH |
39073907
BLOCK_REASSIGNED)))
39083908
{
3909-
struct st_hash_link *UNINIT_VAR(next_hash_link);
3910-
my_off_t UNINIT_VAR(next_diskpos);
3911-
File UNINIT_VAR(next_file);
3912-
uint UNINIT_VAR(next_status);
3913-
uint UNINIT_VAR(hash_requests);
3909+
struct st_hash_link *next_hash_link= NULL;
3910+
my_off_t next_diskpos= 0;
3911+
File next_file= 0;
3912+
uint next_status= 0;
3913+
uint hash_requests= 0;
39143914

39153915
total_found++;
39163916
found++;

mysys/mf_pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static char * expand_tilde(char **path);
2929
void pack_dirname(char * to, const char *from)
3030
{
3131
int cwd_err;
32-
size_t d_length,length,UNINIT_VAR(buff_length);
32+
size_t d_length, length, buff_length= 0;
3333
char * start;
3434
char buff[FN_REFLEN];
3535
DBUG_ENTER("pack_dirname");

mysys/thr_lock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int check_lock(struct st_lock_list *list, const char* lock_type,
126126
{
127127
THR_LOCK_DATA *data,**prev;
128128
uint count=0;
129-
THR_LOCK_INFO *UNINIT_VAR(first_owner);
129+
THR_LOCK_INFO *first_owner= NULL;
130130

131131
prev= &list->data;
132132
if (list->data)

mysys/typelib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option)
6868
int find_type(const char *x, const TYPELIB *typelib, uint flags)
6969
{
7070
int find,pos;
71-
int UNINIT_VAR(findpos); /* guarded by find */
71+
int findpos= 0; /* guarded by find */
7272
const char *i;
7373
const char *j;
7474
DBUG_ENTER("find_type");

regex/regcomp.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ struct parse *p;
216216
int stop; /* character this ERE should end at */
217217
{
218218
char c;
219-
sopno UNINIT_VAR(prevback);
220-
sopno UNINIT_VAR(prevfwd);
219+
sopno prevback= 0;
220+
sopno prevfwd= 0;
221221
sopno conc;
222222
int first = 1; /* is this the first alternative? */
223223

@@ -1498,8 +1498,8 @@ struct parse *p;
14981498
struct re_guts *g;
14991499
{
15001500
sop *scan;
1501-
sop *UNINIT_VAR(start);
1502-
sop *UNINIT_VAR(newstart);
1501+
sop *start= NULL;
1502+
sop *newstart= NULL;
15031503
sopno newlen;
15041504
sop s;
15051505
char *cp;

scripts/mysql_config.pl.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use Cwd;
4242
use strict;
4343

4444
my @exclude_cflags =
45-
qw/DDBUG_OFF DSAFE_MUTEX DFORCE_INIT_OF_VARS
45+
qw/DDBUG_OFF DSAFE_MUTEX
4646
DEXTRA_DEBUG DHAVE_VALGRIND O O[0-9] xO[0-9] W[-A-Za-z]*
4747
unroll2 ip mp restrict/;
4848

scripts/mysql_config.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ cxxflags="-I$pkgincludedir @CXXFLAGS@ " #note: end space!
124124
include="-I$pkgincludedir"
125125

126126
# Remove some options that a client doesn't have to care about
127-
for remove in DDBUG_OFF DSAFE_MUTEX DFORCE_INIT_OF_VARS \
127+
for remove in DDBUG_OFF DSAFE_MUTEX \
128128
DEXTRA_DEBUG DHAVE_VALGRIND O 'O[0-9]' 'xO[0-9]' 'W[-A-Za-z]*' \
129129
'mtune=[-A-Za-z0-9]*' 'mcpu=[-A-Za-z0-9]*' 'march=[-A-Za-z0-9]*' \
130130
unroll2 ip mp restrict

sql-common/my_time.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,19 @@ my_bool
269269
str_to_datetime(const char *str, size_t length, MYSQL_TIME *l_time,
270270
my_time_flags_t flags, MYSQL_TIME_STATUS *status)
271271
{
272-
uint field_length, UNINIT_VAR(year_length), digits, i, number_of_fields;
272+
uint field_length= 0, year_length= 0, digits, i, number_of_fields;
273273
uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
274274
uint add_hours= 0, start_loop;
275275
ulong not_zero_date, allow_space;
276276
my_bool is_internal_format;
277-
const char *pos, *UNINIT_VAR(last_field_pos);
277+
const char *pos, *last_field_pos= NULL;
278278
const char *end=str+length;
279279
const uchar *format_position;
280280
my_bool found_delimitier= 0, found_space= 0;
281281
uint frac_pos, frac_len;
282282
DBUG_ENTER("str_to_datetime");
283283
DBUG_PRINT("ENTER", ("str: %.*s", (int)length, str));
284284

285-
LINT_INIT(field_length);
286-
287285
my_time_status_init(status);
288286

289287
/* Skip space at start */
@@ -676,7 +674,7 @@ my_bool str_to_time(const char *str, size_t length, MYSQL_TIME *l_time,
676674
for (; str != end && my_isspace(&my_charset_latin1, str[0]) ; str++)
677675
;
678676

679-
LINT_INIT(state);
677+
state= 0;
680678
found_days=found_hours=0;
681679
if ((uint) (end-str) > 1 && str != end_of_days &&
682680
my_isdigit(&my_charset_latin1, *str))

sql/auth/sql_authorization.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -2733,13 +2733,12 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user)
27332733
ulong want_access;
27342734
uint counter,index;
27352735
int error = 0;
2736-
ACL_USER *acl_user;
2736+
ACL_USER *acl_user= NULL;
27372737
ACL_DB *acl_db;
27382738
char buff[1024];
27392739
Protocol *protocol= thd->protocol;
27402740
DBUG_ENTER("mysql_show_grants");
27412741

2742-
LINT_INIT(acl_user);
27432742
if (!initialized)
27442743
{
27452744
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");

sql/auth/sql_user.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
554554
int result= 0;
555555
uint idx;
556556
uint elements;
557-
const char *user;
558-
const char *host;
557+
const char *user= NULL;
558+
const char *host= NULL;
559559
ACL_USER *acl_user= NULL;
560560
ACL_DB *acl_db= NULL;
561561
ACL_PROXY_USER *acl_proxy_user= NULL;
@@ -570,9 +570,6 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
570570
DBUG_PRINT("info",("scan struct: %u search: '%s'@'%s'",
571571
struct_no, user_from->user.str, user_from->host.str));
572572

573-
LINT_INIT(user);
574-
LINT_INIT(host);
575-
576573
mysql_mutex_assert_owner(&acl_cache->lock);
577574

578575
/* Get the number of elements in the in-memory structure. */

sql/debug_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
18441844

18451845
if (action->execute)
18461846
{
1847-
const char *UNINIT_VAR(old_proc_info);
1847+
const char *old_proc_info= NULL;
18481848

18491849
action->execute--;
18501850

sql/event_db_repository.cc

-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ Event_db_repository::index_read_for_db_for_i_s(THD *thd, TABLE *schema_table,
410410
KEY *key_info;
411411
uint key_len;
412412
uchar *key_buf= NULL;
413-
LINT_INIT(key_buf);
414413

415414
DBUG_ENTER("Event_db_repository::index_read_for_db_for_i_s");
416415

sql/event_queue.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ Event_queue::get_top_for_execution_if_time(THD *thd,
570570
{
571571
bool ret= FALSE;
572572
*event_name= NULL;
573-
my_time_t UNINIT_VAR(last_executed);
574-
int UNINIT_VAR(status);
573+
my_time_t last_executed= 0;
574+
int status= 0;
575575
DBUG_ENTER("Event_queue::get_top_for_execution_if_time");
576576

577577
LOCK_QUEUE_DATA();

0 commit comments

Comments
 (0)