Rework set_header_word macros
authorMarc Dionne <marc.c.dionne@gmail.com>
Sat, 22 Dec 2012 12:54:54 +0000 (07:54 -0500)
committerDerrick Brashear <shadow@your-file-system.com>
Thu, 31 Jan 2013 10:57:29 +0000 (02:57 -0800)
Rework the set_header_word macros so that all compilers are
happy:
- the use of offsetof() is avoided, as it has an issue on IRIX
when the result is not constant
- the assignment within the macro is explicitely sequenced before
the function call to avoid a gcc sequence-point warning

Change-Id: I2355233e865b155f958379bfa2736fee19ef2680
Reviewed-on: http://gerrit.openafs.org/8816
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/budb/database.h
src/kauth/kadatabase.c

index fdb3da5..3b8f671 100644 (file)
@@ -293,9 +293,11 @@ struct memoryDB {          /* in core copies of database structures */
 extern struct memoryDB db;
 
 #define set_header_word(ut,field,value) \
-    dbwrite ((ut), (offsetof(struct dbHeader, field)), \
-            ((db.h.field = (value)), (char *)&(db.h.field)), \
-            sizeof(afs_int32))
+       ( \
+           (db.h.field) = (value), \
+           dbwrite((ut), ((char *)&(db.h.field) - (char *)&db.h), \
+                   ((char *)&(db.h.field)), sizeof(afs_int32)) \
+       )
 
 #define set_word_offset(ut,a,b,offset,value)                         \
     dbwrite ((ut), (a)+(offset),                                     \
index 9d77106..78f4900 100644 (file)
 
 extern Date cheaderReadTime;   /* time cheader last read in */
 
-#define set_header_word(tt,field,value) kawrite ((tt), (offsetof(struct kaheader, field)), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
+#define set_header_word(tt,field,value) \
+       ( \
+           (cheader.field) = (value), \
+           kawrite((tt), ((char *)&(cheader.field) - (char *)&cheader), \
+                   (char *)&(cheader.field), sizeof(afs_int32)) \
+       )
 
 #define inc_header_word(tt,field) kawrite ((tt), (offsetof(struct kaheader, field)), ((cheader.field = (htonl(ntohl(cheader.field)+1))), (char *)&(cheader.field)), sizeof(afs_int32))