Open Quuxplusone opened 11 years ago
Attached MyAnalyzerTest.zip
(26683 bytes, application/zip): Xcode project demonstrating problem
Yeah, the static analyzer doesn't handle reinterpret_casts very well, and
bitfields don't help either. For what it's worth, though, what you were doing
before is not actually legal according to the C standard (C11 6.5p7):
"An object shall have its stored value accessed only by an lvalue expression
that has one of the following types:
- a type compatible with the effective type of the object,
- a qualified version of a type compatible with the effective type of the
object,
- a type that is the signed or unsigned type corresponding to the effective
type of the object,
- a type that is the signed or unsigned type corresponding to a qualified
version of the effective type of the object,
- an aggregate or union type that includes one of the aforementioned types
among its members (including, recursively, a member of a subaggregate or
contained union), or
- a character type."
So you actually do need the union to do this properly. Or you could use memcpy.
Thanks for the fast response and for including the information from the C standard... I wasn't familiar with that. Feel free to close this as Not to be Fixed. That said, it took me a while to figure out how to correct the issue using the union, so if the analyzer could be magically enhanced to explain why the value is uninitialized it'd probably help others.
Repurposing the bug for this new warning.
MyAnalyzerTest.zip
(26683 bytes, application/zip)