]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
Fix murmur hash seeding
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index d7e325dbde1bad4842063837ac9d17fc3dec0ab1..d1eb5b43754052448cb655dcfa57ae82ba72aa6c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -135,7 +135,7 @@ void *util_memory_r(void *ptrn, size_t byte, unsigned int line, const char *file
 void util_meminfo() {
     struct memblock_t *info;
 
-    if (!opts_memchk)
+    if (!opts.memchk)
         return;
 
     for (info = mem_start; info; info = info->next) {
@@ -246,10 +246,10 @@ bool util_strncmpexact(const char *src, const char *ned, size_t len) {
 
 void util_debug(const char *area, const char *ms, ...) {
     va_list  va;
-    if (!opts_debug)
+    if (!opts.debug)
         return;
 
-    if (!strcmp(area, "MEM") && !opts_memchk)
+    if (!strcmp(area, "MEM") && !opts.memchk)
         return;
 
     va_start(va, ms);
@@ -495,7 +495,7 @@ size_t util_strtononcmd(const char *in, char *out, size_t outsz) {
 
 FILE *util_fopen(const char *filename, const char *mode)
 {
-#ifdef WIN32
+#ifdef _MSC_VER
     FILE *out;
     if (fopen_s(&out, filename, mode) != 0)
         return NULL;
@@ -533,8 +533,8 @@ typedef struct hash_node_t {
  * below.  These should be autovectorized by gcc.
  */
 #ifdef __x86_64__
-GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, register size_t seed) {
-    const uint64_t       mix   = 0xC6A4A7935BD1E995;
+static GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, size_t seed) {
+    const uint64_t       mix   = 0xC6A4A7935BD1E995UL;
     const int            rot   = 47;
     size_t               size  = strlen(key);
     uint64_t             hash  = seed ^ (size - mix);
@@ -575,13 +575,13 @@ GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, registe
 }
 
 #else
-GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, register size_t seed) {
+static GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, size_t seed) {
     const uint32_t       mix   = 0x5BD1E995;
     const uint32_t       rot   = 24;
     size_t               size  = strlen(key);
     uint32_t             hash  = seed ^ size;
     uint32_t             alias = 0;
-    const unsigned char *data  = (const unsigned char*)ket;
+    const unsigned char *data  = (const unsigned char*)key;
 
     while (size >= 4) {
         alias = *(uint32_t*)data;
@@ -615,7 +615,7 @@ GMQCC_INLINE uint32_t util_hthashfunc(hash_table_t *ht, const char *key, registe
 /* we use the crc table as seeds for the murmur hash :P */
 size_t util_hthash(hash_table_t *ht, const char *key) {
     static   size_t seed = 0;
-    register size_t hash = util_hthashfunc(ht, key, util_crc32_table[seed]);
+    register size_t hash = util_hthashfunc(ht, key, util_crc32_table[seed++]);
 
     /* reset seed */
     if (seed >= sizeof(util_crc32_table) / sizeof(*util_crc32_table))