1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Bug#42733: Type-punning warnings when compiling MySQL --

strict aliasing violations.

Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.

As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.

The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
This commit is contained in:
Davi Arnaut
2010-06-10 17:16:43 -03:00
parent e3b4d33187
commit bb036c93b4
35 changed files with 1248 additions and 1111 deletions

View File

@ -45,6 +45,8 @@ static uint find_field(Field **fields, uchar *record, uint start, uint length);
inline bool is_system_table_name(const char *name, uint length);
static ulong get_form_pos(File file, uchar *head);
/**************************************************************************
Object_creation_ctx implementation.
**************************************************************************/
@ -693,7 +695,8 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
disk_buff= 0;
error= 3;
if (!(pos=get_form_pos(file,head,(TYPELIB*) 0)))
/* Position of the form in the form file. */
if (!(pos= get_form_pos(file, head)))
goto err; /* purecov: inspected */
share->frm_version= head[2];
@ -2047,52 +2050,46 @@ void free_field_buffers_larger_than(TABLE *table, uint32 size)
}
}
/* Find where a form starts */
/* if formname is NullS then only formnames is read */
/**
Find where a form starts.
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names)
@param head The start of the form file.
@remark If formname is NULL then only formnames is read.
@retval The form position.
*/
static ulong get_form_pos(File file, uchar *head)
{
uint a_length,names,length;
uchar *pos,*buf;
uchar *pos, *buf;
uint names, length;
ulong ret_value=0;
DBUG_ENTER("get_form_pos");
names=uint2korr(head+8);
a_length=(names+2)*sizeof(char *); /* Room for two extra */
names= uint2korr(head+8);
if (!save_names)
a_length=0;
else
save_names->type_names=0; /* Clear if error */
if (!(names= uint2korr(head+8)))
DBUG_RETURN(0);
if (names)
length= uint2korr(head+4);
my_seek(file, 64L, MY_SEEK_SET, MYF(0));
if (!(buf= (uchar*) my_malloc(length+names*4, MYF(MY_WME))))
DBUG_RETURN(0);
if (my_read(file, buf, length+names*4, MYF(MY_NABP)))
{
length=uint2korr(head+4);
VOID(my_seek(file,64L,MY_SEEK_SET,MYF(0)));
if (!(buf= (uchar*) my_malloc((size_t) length+a_length+names*4,
MYF(MY_WME))) ||
my_read(file, buf+a_length, (size_t) (length+names*4),
MYF(MY_NABP)))
{ /* purecov: inspected */
x_free((uchar*) buf); /* purecov: inspected */
DBUG_RETURN(0L); /* purecov: inspected */
}
pos= buf+a_length+length;
ret_value=uint4korr(pos);
}
if (! save_names)
{
if (names)
my_free((uchar*) buf,MYF(0));
}
else if (!names)
bzero((char*) save_names,sizeof(save_names));
else
{
char *str;
str=(char *) (buf+a_length);
fix_type_pointers((const char ***) &buf,save_names,1,&str);
x_free(buf);
DBUG_RETURN(0);
}
pos= buf+length;
ret_value= uint4korr(pos);
my_free(buf, MYF(0));
DBUG_RETURN(ret_value);
}