[virt-tools-list] [osinfo PATCH] Check PrimaryVolumeDescriptor size at compile-time

Daniel P. Berrange berrange at redhat.com
Mon Jan 9 10:14:33 UTC 2012


On Mon, Jan 09, 2012 at 10:45:22AM +0100, Christophe Fergeau wrote:
> 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 {

ACK


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the virt-tools-list mailing list