]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/make_hash.c
ncurses 6.5 - patch 20240504
[ncurses.git] / ncurses / tinfo / make_hash.c
index 11a10546a925853921372d55e50e510584394b5d..78a684cc8bcb6d0fca93134207e74d79bdc3f5c0 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2019,2020 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2024 Thomas E. Dickey                                *
+ * Copyright 2009-2013,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -43,7 +44,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: make_hash.c,v 1.30 2020/01/18 17:02:38 tom Exp $")
+MODULE_ID("$Id: make_hash.c,v 1.34 2024/03/02 19:35:40 tom Exp $")
 
 /*
  *     _nc_make_hash_table()
@@ -100,13 +101,15 @@ hash_function(const char *string)
     long sum = 0;
 
     while (*string) {
-       sum += (long) (*string + (*(string + 1) << 8));
+       sum += (long) (UChar(*string) + (UChar(*(string + 1)) << 8));
        string++;
     }
 
     return (int) (sum % HASHTABSIZE);
 }
 
+#define UNUSED -1
+
 static void
 _nc_make_hash_table(struct user_table_entry *table,
                    HashValue * hash_table,
@@ -117,7 +120,7 @@ _nc_make_hash_table(struct user_table_entry *table,
     int collisions = 0;
 
     for (i = 0; i < HASHTABSIZE; i++) {
-       hash_table[i] = -1;
+       hash_table[i] = UNUSED;
     }
     for (i = 0; i < tablesize; i++) {
        hashvalue = hash_function(table[i].ute_name);
@@ -125,8 +128,9 @@ _nc_make_hash_table(struct user_table_entry *table,
        if (hash_table[hashvalue] >= 0)
            collisions++;
 
-       if (hash_table[hashvalue] != 0)
+       if (hash_table[hashvalue] != UNUSED) {
            table[i].ute_link = hash_table[hashvalue];
+       }
        hash_table[hashvalue] = (HashValue) i;
     }
 
@@ -246,7 +250,7 @@ main(int argc, char **argv)
     struct user_table_entry *name_table = typeCalloc(struct
                                                     user_table_entry, tablesize);
     HashValue *hash_table = typeCalloc(HashValue, HASHTABSIZE);
-    const char *root_name = "";
+    const char *root_name;
     int column = 0;
     int bigstring = 0;
     unsigned n;