Fix two strict-aliasing errors
NativeReal.c:366:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
NativeReal.c:370:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
diff --git a/skeletons/NativeReal.c b/skeletons/NativeReal.c
index f7bccd4..6f540f1 100644
--- a/skeletons/NativeReal.c
+++ b/skeletons/NativeReal.c
@@ -361,15 +361,24 @@
*/
NativeReal__network_swap(wire_size, ptr, scratch);
+
switch(wire_size) {
- case sizeof(double):
- if(NativeReal__set(td, sptr, *(const double *)scratch) < 0)
- ASN__DECODE_FAILED;
- break;
- case sizeof(float):
- if(NativeReal__set(td, sptr, *(const float *)scratch) < 0)
- ASN__DECODE_FAILED;
- break;
+ case sizeof(double):
+ {
+ double tmp;
+ memcpy(&tmp, scratch, sizeof(double));
+ if(NativeReal__set(td, sptr, tmp) < 0)
+ ASN__DECODE_FAILED;
+ }
+ break;
+ case sizeof(float):
+ {
+ float tmp;
+ memcpy(&tmp, scratch, sizeof(float));
+ if(NativeReal__set(td, sptr, tmp) < 0)
+ ASN__DECODE_FAILED;
+ }
+ break;
default:
ASN__DECODE_FAILED;
}