bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 07/13] exclude: use xwalloc instead of xalloc


From: Paul Eggert
Subject: [PATCH 07/13] exclude: use xwalloc instead of xalloc
Date: Sun, 4 Jun 2017 23:45:57 -0700

* lib/exclude.c: Include xwalloc.h instead of walloc.h.
(struct exclude_pattern, exclude_add_pattern_buffer):
(new_exclude, new_exclude_segment, free_exclude_segment):
(fnmatch_no_wildcards, file_pattern_matches, excluded_file_name):
(add_exclude, add_exclude_fp):
Use xwalloc.h rather than xalloc.h functions.
Use ptrdiff_t, not size_t, for sizes intended for walloc.
* modules/exclude (Depends-on): Add xwalloc, remove xalloc.
---
 ChangeLog       | 10 ++++++++++
 lib/exclude.c   | 44 ++++++++++++++++++++++----------------------
 modules/exclude |  2 +-
 3 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d4173d4..e3be3b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-06-04  Paul Eggert  <address@hidden>
 
+       exclude: use xwalloc instead of xalloc
+       * lib/exclude.c: Include xwalloc.h instead of walloc.h.
+       (struct exclude_pattern, exclude_add_pattern_buffer):
+       (new_exclude, new_exclude_segment, free_exclude_segment):
+       (fnmatch_no_wildcards, file_pattern_matches, excluded_file_name):
+       (add_exclude, add_exclude_fp):
+       Use xwalloc.h rather than xalloc.h functions.
+       Use ptrdiff_t, not size_t, for sizes intended for walloc.
+       * modules/exclude (Depends-on): Add xwalloc, remove xalloc.
+
        acl-permissions: use walloc
        * lib/get-permissions.c: Include walloc.h.
        (get_permissions): Use wreallocarray to fix possible integer overflow.
diff --git a/lib/exclude.c b/lib/exclude.c
index fb3bbc2..17b2d90 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -38,7 +38,7 @@
 #include "hash.h"
 #include "mbuiter.h"
 #include "fnmatch.h"
-#include "xalloc.h"
+#include "xwalloc.h"
 #include "verify.h"
 #include "filename.h"
 
@@ -88,8 +88,8 @@ struct patopts
 struct exclude_pattern
   {
     struct patopts *exclude;
-    size_t exclude_alloc;
-    size_t exclude_count;
+    ptrdiff_t exclude_alloc;
+    ptrdiff_t exclude_count;
   };
 
 enum exclude_type
@@ -131,7 +131,7 @@ struct exclude
 void
 exclude_add_pattern_buffer (struct exclude *ex, char *buf)
 {
-  struct pattern_buffer *pbuf = xmalloc (sizeof *pbuf);
+  struct pattern_buffer *pbuf = xwmalloc (sizeof *pbuf);
   pbuf->base = buf;
   pbuf->next = ex->patbuf;
   ex->patbuf = pbuf;
@@ -190,7 +190,7 @@ unescape_pattern (char *str)
 struct exclude *
 new_exclude (void)
 {
-  return xzalloc (sizeof *new_exclude ());
+  return xwzalloc (sizeof *new_exclude ());
 }
 
 /* Calculate the hash of string.  */
@@ -254,7 +254,7 @@ string_free (void *data)
 static void
 new_exclude_segment (struct exclude *ex, enum exclude_type type, int options)
 {
-  struct exclude_segment *sp = xzalloc (sizeof (struct exclude_segment));
+  struct exclude_segment *sp = xwzalloc (sizeof (struct exclude_segment));
   sp->type = type;
   sp->options = options;
   switch (type)
@@ -281,7 +281,7 @@ new_exclude_segment (struct exclude *ex, enum exclude_type 
type, int options)
 static void
 free_exclude_segment (struct exclude_segment *seg)
 {
-  size_t i;
+  ptrdiff_t i;
 
   switch (seg->type)
     {
@@ -338,7 +338,7 @@ fnmatch_no_wildcards (char const *pattern, char const *f, 
int options)
             : strcmp (pattern, f));
   else if (! (options & FNM_CASEFOLD))
     {
-      size_t patlen = strlen (pattern);
+      ptrdiff_t patlen = strlen (pattern);
       int r = strncmp (pattern, f, patlen);
       if (! r)
         {
@@ -357,7 +357,7 @@ fnmatch_no_wildcards (char const *pattern, char const *f, 
int options)
          Also, the copy should not be necessary.  However, fixing this
          will probably involve a change to the mbs* API.  */
 
-      char *fcopy = xstrdup (f);
+      char *fcopy = xwstrdup (f);
       char *p;
       int r;
       for (p = fcopy; ; *p++ = '/')
@@ -407,9 +407,9 @@ exclude_patopts (struct patopts const *opts, char const *f)
 static bool
 file_pattern_matches (struct exclude_segment const *seg, char const *f)
 {
-  size_t exclude_count = seg->v.pat.exclude_count;
+  ptrdiff_t exclude_count = seg->v.pat.exclude_count;
   struct patopts const *exclude = seg->v.pat.exclude;
-  size_t i;
+  ptrdiff_t i;
 
   for (i = 0; i < exclude_count; i++)
     {
@@ -485,7 +485,7 @@ excluded_file_name (struct exclude const *ex, char const *f)
       if (seg->type == exclude_hash)
         {
           if (!filename)
-            filename = xmalloc (strlen (f) + 1);
+            filename = xwmalloc (strlen (f) + 1);
           if (file_name_matches (seg, f, filename))
             break;
         }
@@ -533,8 +533,8 @@ add_exclude (struct exclude *ex, char const *pattern, int 
options)
 
       pat = &seg->v.pat;
       if (pat->exclude_count == pat->exclude_alloc)
-        pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc,
-                                   sizeof *pat->exclude);
+        pat->exclude = xwgrowalloc (pat->exclude, &pat->exclude_alloc,
+                                    1, -1, sizeof *pat->exclude);
       patopts = &pat->exclude[pat->exclude_count++];
 
       patopts->options = options;
@@ -547,7 +547,7 @@ add_exclude (struct exclude *ex, char const *pattern, int 
options)
          if (options & FNM_LEADING_DIR)
            {
              char *tmp;
-             size_t len = strlen (pattern);
+             ptrdiff_t len = strlen (pattern);
 
              while (len > 0 && ISSLASH (pattern[len-1]))
                --len;
@@ -556,7 +556,7 @@ add_exclude (struct exclude *ex, char const *pattern, int 
options)
                rc = 1;
              else
                {
-                 tmp = xmalloc (len + 7);
+                 tmp = xwmalloc (len + 7);
                  memcpy (tmp, pattern, len);
                  strcpy (tmp + len, "(/.*)?");
                  rc = regcomp (&patopts->v.re, tmp, cflags);
@@ -576,7 +576,7 @@ add_exclude (struct exclude *ex, char const *pattern, int 
options)
        {
          if (options & EXCLUDE_ALLOC)
            {
-             pattern = xstrdup (pattern);
+             pattern = xwstrdup (pattern);
              exclude_add_pattern_buffer (ex, (char*) pattern);
            }
          patopts->v.pattern = pattern;
@@ -593,7 +593,7 @@ add_exclude (struct exclude *ex, char const *pattern, int 
options)
         new_exclude_segment (ex, exclude_hash, options);
       seg = ex->head;
 
-      str = xstrdup (pattern);
+      str = xwstrdup (pattern);
       if ((options & (EXCLUDE_WILDCARDS | FNM_NOESCAPE)) == EXCLUDE_WILDCARDS)
         unescape_pattern (str);
       p = hash_insert (seg->v.table, str);
@@ -617,22 +617,22 @@ add_exclude_fp (void (*add_func) (struct exclude *, char 
const *, int, void *),
   char *p;
   char *pattern;
   char const *lim;
-  size_t buf_alloc = 0;
-  size_t buf_count = 0;
+  ptrdiff_t buf_alloc = 0;
+  ptrdiff_t buf_count = 0;
   int c;
   int e = 0;
 
   while ((c = getc (fp)) != EOF)
     {
       if (buf_count == buf_alloc)
-        buf = x2realloc (buf, &buf_alloc);
+        buf = xwgrowalloc (buf, &buf_alloc, 1, -1, sizeof *buf);
       buf[buf_count++] = c;
     }
 
   if (ferror (fp))
     e = errno;
 
-  buf = xrealloc (buf, buf_count + 1);
+  buf = xwrealloc (buf, buf_count + 1);
   buf[buf_count] = line_end;
   lim = buf + buf_count + ! (buf_count == 0 || buf[buf_count - 1] == line_end);
 
diff --git a/modules/exclude b/modules/exclude
index 04fb0e5..a7e2abb 100644
--- a/modules/exclude
+++ b/modules/exclude
@@ -14,7 +14,7 @@ mbuiter
 regex
 stdbool
 verify
-xalloc
+xwalloc
 
 configure.ac:
 
-- 
2.9.4




reply via email to

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