Bug 779

Summary: Union casting in util/ub_event.c and util/ub_event_pluggable.c is non-portable
Product: unbound Reporter: Richard Lloyd <rkl>
Component: serverAssignee: unbound team <unbound-team>
Status: RESOLVED FIXED    
Severity: normal CC: cathya, ihsan, wouter
Priority: P5    
Version: 1.5.9   
Hardware: Other   
OS: other   

Description Richard Lloyd 2016-06-14 12:14:22 CEST
When compiling unbound 1.5.9 with HP-UX 11.31 using HP's ANSI C compiler, the union casting used in util/ub_event.c and util/ub_event_pluggable.c causes compilation failures because that compiler doesn't support such casting.

For example, util/ub_event.c defines four macros (AS_EVENT_BASE(x), AS_UB_EVENT_BASE(x), AS_EVENT(x) and AS_UB_EVENT(x)) that cast a union type that isn't supported by HP's ANSI C and produce this compiler error:

cc: "util/ub_event.c", line 264: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.
[19 other identical errors later in the file]

The similar macros (AS_MY_EVENT_BASE(x) and AS_MY_EVENT(x)) in util/ub_event_pluggable.c also produced the same sort of error. I'm not sure if union casting is a gcc-only feature, but I suspect other non-gcc compilers may have a similar issue.
Comment 1 Wouter Wijngaards 2016-06-14 12:24:58 CEST
Hi Richard,

I did not know it was nonportable.  It was introduced because of gcc type-punned pointer warnings I think.

Fixed in the code repository.  Thank you for the report.

Best regards, Wouter
Comment 2 Wouter Wijngaards 2016-07-20 14:11:21 CEST
*** Bug 799 has been marked as a duplicate of this bug. ***