Patch by Philipp Thomas <pth@suse.de>:

> Current gcc versions warn when type punning is used, as this breaks the
> strict aliasing analysis gcc 3.3 does by default. When checking the causes
> for these warnings I discovered that sensors_malloc_array,
> sensors_free_array, sensors_add_array_el and sensors_add_array_els in
> lib/general.c all take a 'void **' for the list. This is plain wrong as
> the C standard only allow 'char *' and 'void *' to alias any other type, so
> if these functions should take a generic pointer, it *must* be a 'void *'
> that's internally cast to a 'void **'.
>
> The attached patch does this and adapts all places where these functions are
> called. Note that when done correctly, no cast what-so-ever in the calling
> code is needed.
>
> The patch is against current lm_sensors2 cvs version.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2345 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Mark M. Hoffman committed 2004-03-08 04:39:50 +00:00
1 parent e1c3e50aac
commit 71a96916d5
6 files changed
+38 -32

No files matched your search

+1 -1
View File
@@ -449,7 +449,7 @@ int sensors_do_this_chip_sets(sensors_chip_name name)
break;
if (j != feature_count)
continue;
sensors_add_array_el(&feature_nr,(void **)&feature_list,&feature_count,
sensors_add_array_el(&feature_nr,&feature_list,&feature_count,
&feature_max, sizeof(int));
res = sensors_eval_expr(name,chip->sets[i].value,0,&value);
+4 -4
View File
@@ -32,15 +32,15 @@ static char *buffer;
char sensors_lex_error[100];
#define buffer_malloc() sensors_malloc_array((void **) &buffer,&buffer_count,\
#define buffer_malloc() sensors_malloc_array(&buffer,&buffer_count,\
&buffer_max,1)
#define buffer_free() sensors_free_array((void **) &buffer,&buffer_count,\
#define buffer_free() sensors_free_array(&buffer,&buffer_count,\
&buffer_max)
#define buffer_add_char(c) sensors_add_array_el(c,(void **) &buffer,\
#define buffer_add_char(c) sensors_add_array_el(c,&buffer,\
&buffer_count,\
&buffer_max,1)
#define buffer_add_string(s) sensors_add_array_els(s,strlen(s),\
(void **) &buffer, \
&buffer, \
&buffer_count,&buffer_max,1)
%}
+7 -7
View File
@@ -41,38 +41,38 @@ static sensors_expr *malloc_expr(void);
static sensors_chip *current_chip = NULL;
#define bus_add_el(el) sensors_add_array_el(el,\
(void **) &sensors_config_busses,\
&sensors_config_busses,\
&sensors_config_busses_count,\
&sensors_config_busses_max,\
sizeof(sensors_bus))
#define label_add_el(el) sensors_add_array_el(el,\
(void **) &current_chip->labels,\
&current_chip->labels,\
&current_chip->labels_count,\
&current_chip->labels_max,\
sizeof(sensors_label));
#define set_add_el(el) sensors_add_array_el(el,\
(void **) &current_chip->sets,\
&current_chip->sets,\
&current_chip->sets_count,\
&current_chip->sets_max,\
sizeof(sensors_set));
#define compute_add_el(el) sensors_add_array_el(el,\
(void **) &current_chip->computes,\
&current_chip->computes,\
&current_chip->computes_count,\
&current_chip->computes_max,\
sizeof(sensors_compute));
#define ignore_add_el(el) sensors_add_array_el(el,\
(void **) &current_chip->ignores,\
&current_chip->ignores,\
&current_chip->ignores_count,\
&current_chip->ignores_max,\
sizeof(sensors_ignore));
#define chip_add_el(el) sensors_add_array_el(el,\
(void **) &sensors_config_chips,\
&sensors_config_chips,\
&sensors_config_chips_count,\
&sensors_config_chips_max,\
sizeof(sensors_chip));
#define fits_add_el(el,list) sensors_add_array_el(el,\
(void **) &(list).fits,\
&(list).fits,\
&(list).fits_count,\
&(list).fits_max, \
sizeof(sensors_chip_name));
+20 -14
View File
@@ -27,51 +27,57 @@
#define A_BUNCH 16
void sensors_malloc_array(void **list, int *num_el, int *max_el, int el_size)
void sensors_malloc_array(void *list, int *num_el, int *max_el, int el_size)
{
*list = malloc(el_size*A_BUNCH);
if (! *list)
void **my_list = (void **)list;
*my_list = malloc(el_size*A_BUNCH);
if (! *my_list)
sensors_fatal_error("sensors_malloc_array","Allocating new elements");
*max_el = A_BUNCH;
*num_el = 0;
}
void sensors_free_array(void **list, int *num_el, int *max_el)
void sensors_free_array(void *list, int *num_el, int *max_el)
{
free(*list);
*list = NULL;
void **my_list = (void **)list;
free(*my_list);
*my_list = NULL;
*num_el = 0;
*max_el = 0;
}
void sensors_add_array_el(const void *el, void **list, int *num_el,
void sensors_add_array_el(const void *el, void *list, int *num_el,
int *max_el, int el_size)
{
int new_max_el;
void **my_list = (void *)list;
if (*num_el + 1 > *max_el) {
new_max_el = *max_el + A_BUNCH;
*list = realloc(*list,new_max_el * el_size);
if (! *list)
*my_list = realloc(*my_list,new_max_el * el_size);
if (! *my_list)
sensors_fatal_error("sensors_add_array_el","Allocating new elements");
*max_el = new_max_el;
}
memcpy(((char *) *list) + *num_el * el_size, el, el_size);
memcpy(((char *) *my_list) + *num_el * el_size, el, el_size);
(*num_el) ++;
}
void sensors_add_array_els(const void *els, int nr_els, void **list,
void sensors_add_array_els(const void *els, int nr_els, void *list,
int *num_el, int *max_el, int el_size)
{
int new_max_el;
void **my_list = (void *)list;
if (*num_el + nr_els > *max_el) {
new_max_el = (*max_el + nr_els + A_BUNCH);
new_max_el -= new_max_el % A_BUNCH;
*list = realloc(*list,new_max_el * el_size);
if (! *list)
*my_list = realloc(*my_list,new_max_el * el_size);
if (! *my_list)
sensors_fatal_error("sensors_add_array_els","Allocating new elements");
*max_el = new_max_el;
}
memcpy(((char *)*list) + *num_el * el_size, els, el_size * nr_els);
memcpy(((char *)*my_list) + *num_el * el_size, els, el_size * nr_els);
*num_el += nr_els;
}
+4 -4
View File
@@ -25,12 +25,12 @@
made between the current number of elements and the maximum number.
You can only add elements at the end. Primitive, but very useful
for internal use. */
extern void sensors_malloc_array(void **list, int *num_el, int *max_el,
extern void sensors_malloc_array(void *list, int *num_el, int *max_el,
int el_size);
extern void sensors_free_array(void **list, int *num_el, int *max_el);
extern void sensors_add_array_el(const void *el, void **list, int *num_el,
extern void sensors_free_array(void *list, int *num_el, int *max_el);
extern void sensors_add_array_el(const void *el, void *list, int *num_el,
int *max_el, int el_size);
extern void sensors_add_array_els(const void *els, int nr_els, void **list,
extern void sensors_add_array_els(const void *els, int nr_els, void *list,
int *num_el, int *max_el, int el_size);
/* Strip a string of all terminating spaces */
+2 -2
View File
@@ -60,13 +60,13 @@ int foundsysfs=0;
char sysfsmount[NAME_MAX];
#define add_proc_chips(el) sensors_add_array_el(el,\
(void **) &sensors_proc_chips,\
&sensors_proc_chips,\
&sensors_proc_chips_count,\
&sensors_proc_chips_max,\
sizeof(struct sensors_proc_chips_entry))
#define add_proc_bus(el) sensors_add_array_el(el,\
(void **) &sensors_proc_bus,\
&sensors_proc_bus,\
&sensors_proc_bus_count,\
&sensors_proc_bus_max,\
sizeof(struct sensors_bus))