check for memory exhaustion

hash_initialize returns NULL when out of memory.  Check for it, and
die cleanly instead of crashing.

Reported by 江 祖铭 (Zu-Ming Jiang).
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00015.html

* src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
Check the value returned by hash_initialize.
This commit is contained in:
Akim Demaille
2019-08-31 18:07:26 -05:00
parent 53526f31df
commit f788ba2ab6
5 changed files with 11 additions and 0 deletions

1
THANKS
View File

@@ -199,6 +199,7 @@ Wwp subscript@free.fr
xolodho xolodho@gmail.com xolodho xolodho@gmail.com
Zack Weinberg zack@codesourcery.com Zack Weinberg zack@codesourcery.com
長田偉伸 cbh34680@iret.co.jp 長田偉伸 cbh34680@iret.co.jp
江 祖铭 jjzuming@outlook.com
Many people are not named here because we lost track of them. We Many people are not named here because we lost track of them. We
thank them! Please, help us keeping this list up to date. thank them! Please, help us keeping this list up to date.

View File

@@ -128,6 +128,8 @@ muscle_init (void)
muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
hash_compare_muscles, muscle_entry_free); hash_compare_muscles, muscle_entry_free);
if (!muscle_table)
xalloc_die ();
/* Version and input file. */ /* Version and input file. */
MUSCLE_INSERT_STRING ("version", VERSION); MUSCLE_INSERT_STRING ("version", VERSION);

View File

@@ -364,6 +364,8 @@ state_hash_new (void)
state_hasher, state_hasher,
state_comparator, state_comparator,
NULL); NULL);
if (!state_table)
xalloc_die ();
} }

View File

@@ -778,11 +778,15 @@ symbols_new (void)
hash_symbol_hasher, hash_symbol_hasher,
hash_symbol_comparator, hash_symbol_comparator,
symbol_free); symbol_free);
if (!symbol_table)
xalloc_die ();
semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY, semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY,
NULL, NULL,
hash_semantic_type_hasher, hash_semantic_type_hasher,
hash_semantic_type_comparator, hash_semantic_type_comparator,
free); free);
if (!semantic_type_table)
xalloc_die ();
} }

View File

@@ -162,6 +162,8 @@ uniqstrs_new (void)
hash_uniqstr, hash_uniqstr,
hash_compare_uniqstr, hash_compare_uniqstr,
free); free);
if (!uniqstrs_table)
xalloc_die ();
} }