diffutils-devel
[Top][All Lists]
Advanced

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

[PATCH 04/17] maint: zalloc → xzalloc


From: Paul Eggert
Subject: [PATCH 04/17] maint: zalloc → xzalloc
Date: Sun, 22 Aug 2021 14:02:53 -0700

* src/util.c (zalloc): Remove.  All uses replaced
by xzalloc, which means the same thing.
---
 src/analyze.c |  8 ++++----
 src/diff.h    |  3 ---
 src/io.c      |  2 +-
 src/util.c    | 10 ----------
 4 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/analyze.c b/src/analyze.c
index a5e4bdc..e11f7d4 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -67,7 +67,7 @@ discard_confusing_lines (struct file_data filevec[])
   /* Set up equiv_count[F][I] as the number of lines in file F
      that fall in equivalence class I.  */
 
-  p = zalloc (filevec[0].equiv_max * (2 * sizeof *p));
+  p = xcalloc (filevec[0].equiv_max, 2 * sizeof *p);
   equiv_count[0] = p;
   equiv_count[1] = p + filevec[0].equiv_max;
 
@@ -78,8 +78,8 @@ discard_confusing_lines (struct file_data filevec[])
 
   /* Set up tables of which lines are going to be discarded.  */
 
-  discarded[0] = zalloc (filevec[0].buffered_lines
-                         + filevec[1].buffered_lines);
+  discarded[0] = xzalloc (filevec[0].buffered_lines
+                         + filevec[1].buffered_lines);
   discarded[1] = discarded[0] + filevec[0].buffered_lines;
 
   /* Mark to be discarded each line that matches no line of the other file.
@@ -542,7 +542,7 @@ diff_2_files (struct comparison *cmp)
          Allocate an extra element, always 0, at each end of each vector.  */
 
       size_t s = cmp->file[0].buffered_lines + cmp->file[1].buffered_lines + 4;
-      char *flag_space = zalloc (s);
+      char *flag_space = xzalloc (s);
       cmp->file[0].changed = flag_space + 1;
       cmp->file[1].changed = flag_space + cmp->file[0].buffered_lines + 3;
 
diff --git a/src/diff.h b/src/diff.h
index c469371..a51b9d2 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -389,9 +389,6 @@ extern bool lines_differ (char const *, char const *) 
_GL_ATTRIBUTE_PURE;
 extern lin translate_line_number (struct file_data const *, lin);
 extern struct change *find_change (struct change *);
 extern struct change *find_reverse_change (struct change *);
-extern void *zalloc (size_t)
-  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
-  _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern enum changes analyze_hunk (struct change *, lin *, lin *, lin *, lin *);
 extern void begin_output (void);
 extern void debug_script (struct change *);
diff --git a/src/io.c b/src/io.c
index 1f0e040..77fc070 100644
--- a/src/io.c
+++ b/src/io.c
@@ -806,7 +806,7 @@ read_files (struct file_data filevec[], bool pretend_binary)
   nbuckets = ((size_t) 1 << i) - prime_offset[i];
   if (PTRDIFF_MAX / sizeof *buckets <= nbuckets)
     xalloc_die ();
-  buckets = zalloc ((nbuckets + 1) * sizeof *buckets);
+  buckets = xcalloc (nbuckets + 1, sizeof *buckets);
   buckets++;
 
   for (i = 0; i < 2; i++)
diff --git a/src/util.c b/src/util.c
index 4348757..b5efb59 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1546,16 +1546,6 @@ concat (char const *s1, char const *s2, char const *s3)
   sprintf (new, "%s%s%s", s1, s2, s3);
   return new;
 }
-
-/* Yield a new block of SIZE bytes, initialized to zero.  */
-
-void *
-zalloc (size_t size)
-{
-  void *p = xmalloc (size);
-  memset (p, 0, size);
-  return p;
-}
 
 void
 debug_script (struct change *sp)
-- 
2.31.1




reply via email to

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