]> Savannah Git Hosting - gnulib.git/commitdiff
regex: use re_malloc etc. consistently
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 19 Dec 2017 23:53:47 +0000 (15:53 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 19 Dec 2017 23:56:19 +0000 (15:56 -0800)
Problem and original patch reported by Arnold Robbins in:
https://sourceware.org/ml/libc-alpha/2017-12/msg00241.html
* lib/regcomp.c (re_comp):
* lib/regexec.c (push_fail_stack, build_trtable, match_ctx_clean):
Use re_malloc/re_realloc/re_free instead of malloc/realloc/free.

ChangeLog
lib/regcomp.c
lib/regexec.c

index 2c838329fb8f4a2f930bacc842ecc7506012ad4d..7d7b10aa2999e82b1da8b15d95b225fbac772d73 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-12-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       regex: use re_malloc etc. consistently
+       Problem and original patch reported by Arnold Robbins in:
+       https://sourceware.org/ml/libc-alpha/2017-12/msg00241.html
+       * lib/regcomp.c (re_comp):
+       * lib/regexec.c (push_fail_stack, build_trtable, match_ctx_clean):
+       Use re_malloc/re_realloc/re_free instead of malloc/realloc/free.
+
 2017-12-15  Tim Rühsen  <tim.ruehsen@gmx.de>
             Paul Eggert  <eggert@cs.ucla.edu>
 
index 88539ad3e49944a6af8b80b456bec1ce106afd00..b4bc3735369dd8a1b5cdafa681e6d7544422bc0a 100644 (file)
@@ -701,7 +701,7 @@ re_comp (const char *s)
 
   if (re_comp_buf.fastmap == NULL)
     {
-      re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
+      re_comp_buf.fastmap = re_malloc (char, SBC_MAX);
       if (re_comp_buf.fastmap == NULL)
        return (char *) gettext (__re_error_msgid
                                 + __re_error_msgid_idx[(int) REG_ESPACE]);
@@ -1197,7 +1197,7 @@ analyze (regex_t *preg)
          break;
       if (i == preg->re_nsub)
        {
-         free (dfa->subexp_map);
+         re_free (dfa->subexp_map);
          dfa->subexp_map = NULL;
        }
     }
index 262384cfc149c8ee1ca5aac2504816a7d92e0d9b..5d7ba2a33b04c2e0f3abea37c5a5c21b54a7e416 100644 (file)
@@ -1334,8 +1334,8 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
   if (fs->num == fs->alloc)
     {
       struct re_fail_stack_ent_t *new_array;
-      new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
-                                      * fs->alloc * 2));
+      new_array = re_realloc (fs->stack, struct re_fail_stack_ent_t,
+                              fs->alloc * 2);
       if (new_array == NULL)
        return REG_ESPACE;
       fs->alloc *= 2;
@@ -3319,7 +3319,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
   if (BE (ndests <= 0, 0))
     {
       if (dests_node_malloced)
-       free (dests_alloc);
+       re_free (dests_alloc);
       /* Return false in case of an error, true otherwise.  */
       if (ndests == 0)
        {
@@ -3349,18 +3349,17 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
       alloca (ndests * 3 * sizeof (re_dfastate_t *));
   else
     {
-      dest_states = (re_dfastate_t **)
-       malloc (ndests * 3 * sizeof (re_dfastate_t *));
+      dest_states = re_malloc (re_dfastate_t *, ndests * 3);
       if (BE (dest_states == NULL, 0))
        {
 out_free:
          if (dest_states_malloced)
-           free (dest_states);
+           re_free (dest_states);
          re_node_set_free (&follows);
          for (i = 0; i < ndests; ++i)
            re_node_set_free (dests_node + i);
          if (dests_node_malloced)
-           free (dests_alloc);
+           re_free (dests_alloc);
          return false;
        }
       dest_states_malloced = true;
@@ -3491,14 +3490,14 @@ out_free:
     }
 
   if (dest_states_malloced)
-    free (dest_states);
+    re_free (dest_states);
 
   re_node_set_free (&follows);
   for (i = 0; i < ndests; ++i)
     re_node_set_free (dests_node + i);
 
   if (dests_node_malloced)
-    free (dests_alloc);
+    re_free (dests_alloc);
 
   return true;
 }
@@ -4166,7 +4165,7 @@ match_ctx_clean (re_match_context_t *mctx)
          re_free (top->path->array);
          re_free (top->path);
        }
-      free (top);
+      re_free (top);
     }
 
   mctx->nsub_tops = 0;