/****************************************************************************
- * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc. *
+ * Copyright 2018-2019,2020 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 *
#include <ctype.h>
-MODULE_ID("$Id: make_hash.c,v 1.26 2019/03/10 01:10:15 tom Exp $")
+MODULE_ID("$Id: make_hash.c,v 1.33 2020/02/02 23:34:34 tom Exp $")
/*
* _nc_make_hash_table()
*
* Computes the hashing function on the given string.
*
- * The current hash function is the sum of each consectutive pair
+ * The current hash function is the sum of each consecutive pair
* of characters, taken as two-byte integers, mod HASHTABSIZE.
*
*/
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,
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);
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;
}
int col = 0;
-#if NO_LEAKS
if (buffer == 0) {
free(list);
list = 0;
return 0;
}
-#endif
if (*buffer != '#') {
if (list == 0) {
static char *
get_type(int type_mask)
{
- static char result[40];
+ static char result[80];
unsigned n;
- strcpy(result, L_PAREN);
+ _nc_STRCPY(result, L_PAREN, sizeof(result));
for (n = 0; n < 3; ++n) {
if ((1 << n) & type_mask) {
+ size_t want = 5 + strlen(typenames[n]);
+ if (want > sizeof(result)) {
+ fprintf(stderr, "Buffer is not large enough for %s + %s\n",
+ result, typenames[n]);
+ exit(EXIT_FAILURE);
+ }
if (result[1])
- strcat(result, "|");
- strcat(result, "1<<");
- strcat(result, typenames[n]);
+ _nc_STRCAT(result, "|", sizeof(result));
+ _nc_STRCAT(result, "1<<", sizeof(result));
+ _nc_STRCAT(result, typenames[n], sizeof(result));
}
}
- strcat(result, R_PAREN);
+ _nc_STRCAT(result, R_PAREN, sizeof(result));
return result;
}
}
free(hash_table);
-#if NO_LEAKS
for (n = 0; (n < tablesize); ++n) {
free((void *) name_table[n].ute_name);
}
free(name_table);
parse_columns(0);
-#endif
+
return EXIT_SUCCESS;
}