bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Null-Dereference bug in hash.c


From: Akim Demaille
Subject: Re: Null-Dereference bug in hash.c
Date: Tue, 10 Sep 2019 07:38:57 +0200

Hi Egor,

> Le 9 sept. 2019 à 01:15, Egor Pugin <address@hidden> a écrit :
> 
>> Installed in master.
> 
> Hi,
> 
> Quick note about your changes. It seems all places with 'var =
> hash_initialize()' have the following check:
> if (!var)
>    xalloc_die ();
> 
> Probably, it will be more... programmish if you make and add
> xhash_initialize() function with that check in it.
> DRY.

Yeah, I know.  But I was lazy and decided to follow the pattern followed by the 
GNU Coreutils rather than pushing an upgrading to hash.

But you convinced me, and I did it.  I just pushed this in maint and master:

commit 730936cdb8b58cfc6f59a060db4b5f5df9c447a8
Author: Akim Demaille <address@hidden>
Date:   Mon Sep 9 19:40:31 2019 +0200

    gnulib: update
    
    Contains the creation of the xhash module.
    https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00046.html
    
    * src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
    Use hash_xinitialize.

diff --git a/bootstrap.conf b/bootstrap.conf
index 0d379797..44469581 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -25,7 +25,7 @@ gnulib_modules='
   error extensions fdl fopen-safer
   getopt-gnu
   gettext-h git-version-gen gitlog-to-changelog
-  gpl-3.0 hash inttypes isnan javacomp-script
+  gpl-3.0 inttypes isnan javacomp-script
   javaexec-script
   ldexpl
   libtextstyle-optional
@@ -48,6 +48,7 @@ gnulib_modules='
   xalloc
   xalloc-die
   xconcat-filename
+  xhash
   xlist
   xmemdup0
   xstrndup
diff --git a/gnulib b/gnulib
index 03add7eb..672663ac 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 03add7eb9d06ab509034ba01c904a4cb36f5706b
+Subproject commit 672663aca33a8fac097f114693f69f09896ea62d
diff --git a/lib/.gitignore b/lib/.gitignore
index 344caefd..39a21e68 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -321,3 +321,4 @@
 /assure.h
 /fsync.c
 /textstyle.in.h
+/xhash.c
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index d3e358e6..91a45737 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -126,10 +126,8 @@ muscle_init (void)
   /* Initialize the muscle obstack.  */
   obstack_init (&muscle_obstack);
 
-  muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
-                                  hash_compare_muscles, muscle_entry_free);
-  if (!muscle_table)
-    xalloc_die ();
+  muscle_table = hash_xinitialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
+                                   hash_compare_muscles, muscle_entry_free);
 
   /* Version and input file.  */
   MUSCLE_INSERT_STRING ("version", VERSION);
diff --git a/src/state.c b/src/state.c
index 64bb256c..418f3fab 100644
--- a/src/state.c
+++ b/src/state.c
@@ -359,13 +359,11 @@ state_hasher (void const *s, size_t tablesize)
 void
 state_hash_new (void)
 {
-  state_table = hash_initialize (HT_INITIAL_CAPACITY,
-                                 NULL,
-                                 state_hasher,
-                                 state_comparator,
-                                 NULL);
-  if (!state_table)
-    xalloc_die ();
+  state_table = hash_xinitialize (HT_INITIAL_CAPACITY,
+                                  NULL,
+                                  state_hasher,
+                                  state_comparator,
+                                  NULL);
 }
 
 
diff --git a/src/symtab.c b/src/symtab.c
index 7b0439ad..417b71e4 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -779,20 +779,16 @@ hash_semantic_type_hasher (void const *m, size_t 
tablesize)
 void
 symbols_new (void)
 {
-  symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
-                                  NULL,
-                                  hash_symbol_hasher,
-                                  hash_symbol_comparator,
-                                  symbol_free);
-  if (!symbol_table)
-    xalloc_die ();
-  semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY,
-                                         NULL,
-                                         hash_semantic_type_hasher,
-                                         hash_semantic_type_comparator,
-                                         free);
-  if (!semantic_type_table)
-    xalloc_die ();
+  symbol_table = hash_xinitialize (HT_INITIAL_CAPACITY,
+                                   NULL,
+                                   hash_symbol_hasher,
+                                   hash_symbol_comparator,
+                                   symbol_free);
+  semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY,
+                                          NULL,
+                                          hash_semantic_type_hasher,
+                                          hash_semantic_type_comparator,
+                                          free);
 }
 
 
diff --git a/src/uniqstr.c b/src/uniqstr.c
index d5c66846..3833b841 100644
--- a/src/uniqstr.c
+++ b/src/uniqstr.c
@@ -157,13 +157,11 @@ hash_uniqstr (void const *m, size_t tablesize)
 void
 uniqstrs_new (void)
 {
-  uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY,
-                                    NULL,
-                                    hash_uniqstr,
-                                    hash_compare_uniqstr,
-                                    free);
-  if (!uniqstrs_table)
-    xalloc_die ();
+  uniqstrs_table = hash_xinitialize (HT_INITIAL_CAPACITY,
+                                     NULL,
+                                     hash_uniqstr,
+                                     hash_compare_uniqstr,
+                                     free);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]