[virt-tools-list] [osinfo PATCH] Check PrimaryVolumeDescriptor size at compile-time
Christophe Fergeau
cfergeau at redhat.com
Mon Jan 9 09:45:22 UTC 2012
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
More information about the virt-tools-list
mailing list