X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcomp_hash.c;h=4b081afa2c2842d1ef18587c53ddd4d766472908;hb=d1a029866f6d84087781eaa81de19949d8533426;hp=21f165ca2e42bd0ac65d10f8016cb6cab5b4ab95;hpb=cdaf29481becd3e1c21baa574ac1ab88ea5f3d38;p=ncurses.git diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c index 21f165ca..4b081afa 100644 --- a/ncurses/tinfo/comp_hash.c +++ b/ncurses/tinfo/comp_hash.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2019 Free Software Foundation, Inc. * + * Copyright 2019-2020,2023 Thomas E. Dickey * + * Copyright 1998-2008,2009 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 * @@ -44,13 +45,12 @@ #include #include -MODULE_ID("$Id: comp_hash.c,v 1.49 2019/03/10 00:06:48 tom Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.55 2023/06/24 13:29:43 tom Exp $") /* * Finds the entry for the given string in the hash table if present. * Returns a pointer to the entry in the table or 0 if not found. */ -/* entrypoint used by tack (do not alter) */ NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry(const char *string, const HashValue * hash_table) @@ -63,7 +63,9 @@ _nc_find_entry(const char *string, hashvalue = data->hash_of(string); - if (data->table_data[hashvalue] >= 0) { + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { real_table = _nc_get_table(termcap); ptr = real_table + data->table_data[hashvalue]; @@ -96,17 +98,21 @@ _nc_find_type_entry(const char *string, const HashData *data = _nc_get_hash_info(termcap); int hashvalue = data->hash_of(string); - if (data->table_data[hashvalue] >= 0) { + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { const struct name_table_entry *const table = _nc_get_table(termcap); - ptr = table + data->table_data[hashvalue]; - while (ptr->nte_type != type - || !data->compare_names(ptr->nte_name, string)) { - if (ptr->nte_link < 0) { - ptr = 0; - break; + if (table != NULL) { + ptr = table + data->table_data[hashvalue]; + while (ptr->nte_type != type + || !data->compare_names(ptr->nte_name, string)) { + if (ptr->nte_link < 0) { + ptr = 0; + break; + } + ptr = table + (ptr->nte_link + data->table_data[data->table_size]); } - ptr = table + (ptr->nte_link + data->table_data[data->table_size]); } } @@ -124,7 +130,9 @@ _nc_find_user_entry(const char *string) hashvalue = data->hash_of(string); - if (data->table_data[hashvalue] >= 0) { + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { real_table = _nc_get_userdefs_table(); ptr = real_table + data->table_data[hashvalue];