[DVDnav-discuss] [PATCH] Fix strict-aliasing warnings

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue Nov 6 20:52:50 CET 2012


Hello,
gcc complains about this both in SVN and Erik's git repo.
Using a union is supposedly safe for gcc at least, but I don't know
about other compilers.
I think the bitfield is simply a bad idea in general...
An alternative would be to use memcpy.

Index: libdvdnav/dvdnav.c
===================================================================
--- libdvdnav/dvdnav.c	(revision 1243)
+++ libdvdnav/dvdnav.c	(working copy)
@@ -1162,7 +1161,7 @@
   union {
     user_ops_t ops_struct;
     uint32_t   ops_int;
-  } ops;
+  } ops, tmp;
 
   ops.ops_int = 0;
 
@@ -1172,10 +1171,12 @@
   }
 
   pthread_mutex_lock(&this->vm_lock);
-  ops.ops_int |= *(uint32_t*)&this->pci.pci_gi.vobu_uop_ctl;
+  ops.ops_struct = this->pci.pci_gi.vobu_uop_ctl;
 
-  if(this->vm && this->vm->state.pgc)
-    ops.ops_int |= *(uint32_t*)&this->vm->state.pgc->prohibited_ops;
+  if(this->vm && this->vm->state.pgc) {
+    tmp.ops_struct = this->vm->state.pgc->prohibited_ops;
+    ops.ops_int |= tmp.ops_int;
+  }
   pthread_mutex_unlock(&this->vm_lock);
 
   return ops.ops_struct;



More information about the DVDnav-discuss mailing list