]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib:replace add discard_align_p
authorGary Lockyer <gary@catalyst.net.nz>
Wed, 18 Mar 2026 00:25:44 +0000 (13:25 +1300)
committerVolker Lendecke <vl@samba.org>
Fri, 20 Mar 2026 13:27:34 +0000 (13:27 +0000)
Add discard_align_p macro to allow the suppression of cast-align warnings

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/replace/replace.h

index 051583cecc71bed0241b91b7b4b1fabd4b140d9b..8c0c572fbc8aa08ce891722f2d6d92659bc50e6d 100644 (file)
@@ -800,6 +800,26 @@ typedef unsigned long long ptrdiff_t ;
 /** Type-safe version of discard_const */
 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
 
+/*
+ * Hack to suppress clang cast-align warnings.
+ *
+ * Before using this macro:
+ *    can you copy the data using memcpy?
+ *    can you call talloc_get_type_abort?
+ *
+ * If using
+ *    was the data allocated with talloc/malloc, in that case it should
+ *    be correctly aligned
+ *
+ *    consider using check_alignment from lib/util/alignment.h to verify
+ *    the alignment.
+ *
+ * call via the discard_align_p macro to maintain type safety
+ *
+ */
+#define discard_align(ptr) ((void *)((uintptr_t)(ptr)))
+#define discard_align_p(type, ptr) ((type *)discard_align(ptr))
+
 #ifndef __STRING
 #define __STRING(x)    #x
 #endif