| Summary: | sane-backends-1.0.19-r2 has "dereferencing type-punned pointer" warnings with gcc 4.1.2 | ||
|---|---|---|---|
| Product: | Gentoo Linux | Reporter: | John Whitlock <John-Whitlock> |
| Component: | Current packages | Assignee: | Patrick Kursawe (RETIRED) <phosphan> |
| Status: | RESOLVED FIXED | ||
| Severity: | minor | CC: | truedfx |
| Priority: | High | ||
| Version: | unspecified | ||
| Hardware: | AMD64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Package list: | Runtime testing required: | --- | |
| Attachments: |
New ebuild that applies patch
Patch to cast to (void *) and eliminate warning adds -fno-strict-aliasing cflag to build |
||
|
Description
John Whitlock
2009-01-03 00:19:29 UTC
Created attachment 177169 [details]
New ebuild that applies patch
Created attachment 177170 [details, diff]
Patch to cast to (void *) and eliminate warning
> The solution is to cast to (void *) before casting to (void **).
No, absolutely not. That extra cast does nothing whatsoever to fix the problem. It merely tells gcc "shut up, I know what I'm doing", and should be used only when you really do.
Created attachment 177177 [details]
adds -fno-strict-aliasing cflag to build
Reading the gcc manual and the code, I think this is a case where masking the warning is the right thing. They are using a union to save memory, setting an enumeration to set which union member was written to, etc. In other words, all the things you do to try to simulate C++ polymorphism in C.
However, it is upstream's job to decide if they want to mask the warning or write code that gcc is more comfortable with, so I'm removing the patch. I've replaced it with an ebuild that sets the -fno-strict-aliasing flag instead.
(In reply to comment #4) > Reading the gcc manual and the code, I think this is a case where masking the > warning is the right thing. They are using a union to save memory, setting an > enumeration to set which union member was written to, etc. In other words, all > the things you do to try to simulate C++ polymorphism in C. That's not what the warning is about. If you look at the first hunk, referring to a->desc, that's declared in sane_net.h as typedef struct { SANE_Word num_options; SANE_Option_Descriptor **desc; } SANE_Option_Descriptor_Array; A SANE_Option_Descriptor ** is not a void *, and you cannot access it as if it were. Reading from and writing to *(void **) &a->desc means about as much as reading from *(long **) &i, where i is an int: it makes no sense on some systems if they are represented differently, because of that it's just plain not allowed by C, and because of that gcc will optimise on the assumption that you don't do that. > However, it is upstream's job to decide if they want to mask the warning or > write code that gcc is more comfortable with, so I'm removing the patch. I've > replaced it with an ebuild that sets the -fno-strict-aliasing flag instead. Thank you. -fno-strict-aliasing is one of the right possible answers here. Since this seems to be more a potential problem than real breakage I have fixed it silently for all current ebuilds. Thanks guys! |