[osinfo PATCH] Check PrimaryVolumeDescriptor size at compile-time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Blake suggested on the mailing list that we can use a dummy
array declaration to trigger a compile error if the
PrimaryVolumeDescriptor structure size isn't 2048 bytes.
---
 osinfo/osinfo_media.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 15d6abe..53d362c 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -46,6 +46,13 @@ struct _PrimaryVolumeDescriptor {
     guint8 ignored3[1602];
 } __attribute__ ((packed));
 
+/* the PrimaryVolumeDescriptor struct must exactly 2048 bytes long
+ * since we expect the supplementary volume descriptor to be right
+ * after it. The magic declaration below ensures we get a compilatin
+ * error if its size is not correct
+ */
+char dummy[sizeof(struct _PrimaryVolumeDescriptor) == 2048 ? 1 : -1];
+
 typedef struct _SupplementaryVolumeDescriptor SupplementaryVolumeDescriptor;
 
 struct _SupplementaryVolumeDescriptor {
-- 
1.7.7.5


[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux