From 650f0a6c66a9debb71e9cdab5ba7494f97206e59 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 18 Apr 2021 16:05:30 -0700
Subject: [PATCH] backupfile: simplify via realloc-gnu

* lib/backupfile.c: Do not include xalloc-oversized.h.
(numbered_backup): Simplify now that realloc will do the right
thing about ptrdiff_t overflow.
* modules/backupfile (Depends-on): Add realloc-gnu;
remove xalloc-oversized.
---
 ChangeLog          | 7 +++++++
 lib/backupfile.c   | 3 +--
 modules/backupfile | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d2d12058eb..e00a5b7c84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-04-18  Paul Eggert  <eggert@cs.ucla.edu>
 
+	backupfile: simplify via realloc-gnu
+	* lib/backupfile.c: Do not include xalloc-oversized.h.
+	(numbered_backup): Simplify now that realloc will do the right
+	thing about ptrdiff_t overflow.
+	* modules/backupfile (Depends-on): Add realloc-gnu;
+	remove xalloc-oversized.
+
 	safe-alloc: improve doc
 	* doc/safe-alloc.texi: Clarify that reallocating an array appends
 	uninitialized storage.  Say ‘sizeof *p’ rather than ‘sizeof(*p)’
diff --git a/lib/backupfile.c b/lib/backupfile.c
index 1e427e8def..bc03dd6146 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -37,7 +37,6 @@
 #include "intprops.h"
 #include "opendirat.h"
 #include "renameatu.h"
-#include "xalloc-oversized.h"
 
 #ifndef _D_EXACT_NAMLEN
 # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
@@ -271,7 +270,7 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
       size_t new_buffer_size = filelen + 2 + versionlenmax + 2;
       if (buffer_size < new_buffer_size)
         {
-          xalloc_count_t grown;
+          size_t grown;
           if (! INT_ADD_WRAPV (new_buffer_size, new_buffer_size >> 1, &grown))
             new_buffer_size = grown;
           char *new_buf = realloc (buf, new_buffer_size);
diff --git a/modules/backupfile b/modules/backupfile
index 42c8c9ed53..342a7bdff1 100644
--- a/modules/backupfile
+++ b/modules/backupfile
@@ -21,11 +21,11 @@ intprops
 memcmp
 opendirat
 readdir
+realloc-gnu
 renameatu
 stdbool
 stdint
 xalloc-die
-xalloc-oversized
 
 configure.ac:
 gl_BACKUPFILE
-- 
2.39.5