Don't cast the return from realloc()
[openafs.git] / src / kauth / kadatabase.c
index b204225..5d59ba2 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
-#include <string.h>
 #include <ubik.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <afs/afsutil.h>
+
 #include "kauth.h"
 #include "kautils.h"
 #include "kaserver.h"
 
+#if !defined(offsetof)
+#include <stddef.h>             /* for definition of offsetof() */
+#endif
+
 extern Date cheaderReadTime;   /* time cheader last read in */
 
-#define set_header_word(tt,field,value) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
+#define set_header_word(tt,field,value) kawrite ((tt), (offsetof(struct kaheader, field)), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
 
-#define inc_header_word(tt,field) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (htonl(ntohl(cheader.field)+1))), (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))
 
 static int index_OK(afs_int32);
 
@@ -411,7 +410,10 @@ ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
     Date now = time(0);
     afs_int32 newkeyver;       /* new key version number */
     afs_int32 newtotalkeyentries = 0, oldtotalkeyentries = 0, keyentries;
-    int foundcurrentkey = 0, addednewkey = 0, modified;
+    int addednewkey = 0, modified;
+#ifdef AUTH_DBM_LOG
+    int foundcurrentkey = 0;
+#endif
 
     es_Report("Newkey for %s.%s\n", tentry->userID.name,
              tentry->userID.instance);
@@ -460,8 +462,8 @@ ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
                            ("Warning: Entry %s.%s contains more than one valid key: fixing\n",
                             tentry->userID.name, tentry->userID.instance));
                }
-#endif
                foundcurrentkey = 1;
+#endif
            }
 
            /* If we find an oldkey of the same version or
@@ -704,10 +706,8 @@ ka_Encache(char *name, char *inst, afs_int32 kvno,
            return;
        }
     /* i == maxCachedKeys */
-    keyCache =
-       (struct cachedKey *)realloc(keyCache,
-                                   (maxCachedKeys *=
-                                    2) * sizeof(struct cachedKey));
+    keyCache = realloc(keyCache, (maxCachedKeys *=2)
+                                 * sizeof(struct cachedKey));
     if (keyCache == 0) {
        es_Report("Can't realloc keyCache! out of memory?");
        exit(123);