From 4f428ea6db1fac76015a056be1506b86fb443399 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 19 Jul 2021 22:28:22 +0100 Subject: [PATCH] `TRANSMUTE()`: Fix input type size not being properly checked. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for naka's current commit: Blessing − 吉 --- include/macros.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/macros.h b/include/macros.h index ead8d6b..e4ada05 100644 --- a/include/macros.h +++ b/include/macros.h @@ -209,6 +209,7 @@ static_assert_eq(bswap(bswap(128lu)), 128, "bswap128 (lu) failed (3)"); // Transmute #define TRANSMUTE(val, type) ({ union _trans { var(val) input; type output; }; \ + _Static_assert(sizeof(var(val)) == sizeof(type), "Cannot transmute values of different sizes"); \ _Static_assert(sizeof(union _trans) == sizeof(type), "Cannot transmute values of different sizes"); \ /* XXX: Do we need do check this for equality? Can we re-word it or do we even need it at all? _Static_assert(_Alignof(union _trans) == _Alignof(type), "Cannot transmute values of different alignments");*/ \ union _trans _trans__value = { .input = (val), }; \