Fix for type punning in lm_sensors2
Skipped content of type multipart/mixed-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040305/4221e071/attachment.bin
Mark M. Hoffman
AppliedQuoted 9 lines · Philipp Thomas
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_elandsensors_add_array_elsinlib/general.call 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 **'.
Hmmm... "gcc (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)" doesn't throw any warnings about this. What version do you use?
Quoted 3 lines
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.
Yes that does read better.
Quoted 1 line
The patch is against current
lm_sensors2cvs version.
I've applied it - thanks!
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]
Quoted 2 lines · * Mark M. Hoffman ([email protected]) [20040308 05:37]:
Hmmm... "gcc (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)" doesn't throw any warnings about this.
Even when given -Wall?
Quoted 1 line
What version do you use?
gcc (GCC) 3.3.2 (SuSE Linux)
The warnings from the compiler where what got me startet in the first place because this warning is among those that will make the package fail in our automatic build system. And instead of using -fno-strict-aliasing I decided to fix the code instead.
Quoted 1 line
Yes that does read better.
My rule of thumb: if it needs casts it needs serious reconsideration :)
Quoted 1 line
I've applied it - thanks!
Thanks for applying it so quick. One patch less to maintain :)
Philipp
Signature · 2 lines
Philipp Thomas <pth AT suse DOT de> SUSE LINUX AG, Maxfeldstr. 5, D-90409 Nuremberg, Germany