aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarehbein <arehbein@sysmocom.de>2023-09-16 22:41:22 +0200
committerarehbein <arehbein@sysmocom.de>2023-09-19 12:30:19 +0200
commit35fcd6025d92c196e70a90c5bb7d85ead0b43f7a (patch)
tree6e48763d6394fa1bc28c2c20c297d178de70928b
parentfd2eaea8246f8125cb526b0d2f248546fdbf1221 (diff)
ipa: Don't break strict aliasing rule
Somehow gcc doesn't always warn about this rule being broken. We are breaking the strict aliasing rule here and libosmo-netif currently does not make use of the '-fno-strict-aliasing' flag. It's possible that this has also been causing nondeterministic timestamps in libosmo-netif stream tests every once in a while. Related: OS#6164, OS#5753 Change-Id: Ibed543cdfcdda8c0256ce7d8818ff96d6d46e9b0
-rw-r--r--include/osmocom/netif/ipa.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/include/osmocom/netif/ipa.h b/include/osmocom/netif/ipa.h
index 1923253..7826895 100644
--- a/include/osmocom/netif/ipa.h
+++ b/include/osmocom/netif/ipa.h
@@ -23,7 +23,19 @@ struct osmo_ipa_msgb_cb {
uint8_t proto_ext;
} __attribute__ ((packed));
-#define OSMO_IPA_MSGB_CB(__msg) ((struct osmo_ipa_msgb_cb *)&((__msg)->cb[0]))
+
+/* We don't just cast to 'struct osmo_ipa_msgb_cb *', because that would
+ * break the strict aliasing rule. Casting to a reference to a union with
+ * a compatible struct member seems to be allowed, though, see:
+ * N1570 Committee Draft — April 12, 2011 ISO/IEC 9899:201x,
+ * Section 6.5, §7 */
+#define OSMO_IPA_MSGB_CB(__msg) (&((( \
+ union { \
+ unsigned long cb; \
+ struct osmo_ipa_msgb_cb _cb; \
+ } \
+ *)&((__msg)->cb[0]))->_cb))
+
#define osmo_ipa_msgb_cb_proto(__x) OSMO_IPA_MSGB_CB(__x)->proto
#define osmo_ipa_msgb_cb_proto_ext(__x) OSMO_IPA_MSGB_CB(__x)->proto_ext