]> Savannah Git Hosting - gnulib.git/commitdiff
backupfile: less-aggressive buffer growth
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Apr 2021 00:39:31 +0000 (17:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Apr 2021 00:51:35 +0000 (17:51 -0700)
* lib/backupfile.c: Include intprops.h.
(numbered_backup): Grow buffer by the usual 50%, not 100%.
This is easier to do now that we have xalloc_count_t.
* modules/backup-rename, modules/backupfile: Depend on intprops.

ChangeLog
lib/backupfile.c
modules/backup-rename
modules/backupfile

index 0c3ea48fe8c831557560072ff47790abcb2b6f8f..c68da0df85665511e728fdae7ee1f37db6f893db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2021-04-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       backupfile: less-aggressive buffer growth
+       * lib/backupfile.c: Include intprops.h.
+       (numbered_backup): Grow buffer by the usual 50%, not 100%.
+       This is easier to do now that we have xalloc_count_t.
+       * modules/backup-rename, modules/backupfile: Depend on intprops.
+
        xalloc-oversized: export xalloc_count_t
        * lib/xalloc-oversized.h (__xalloc_oversized, xalloc_oversized):
        * lib/xmalloca.h (nmalloca):
index c53e3f335aa5478fbbf451b582027bd1e6c6cf84..1e427e8def4d55f6228d3d19f834eed965bfcc25 100644 (file)
@@ -34,6 +34,7 @@
 #include "attribute.h"
 #include "basename-lgpl.h"
 #include "idx.h"
+#include "intprops.h"
 #include "opendirat.h"
 #include "renameatu.h"
 #include "xalloc-oversized.h"
@@ -270,8 +271,9 @@ 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)
         {
-          if (! xalloc_oversized (new_buffer_size, 2))
-            new_buffer_size *= 2;
+          xalloc_count_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);
           if (!new_buf)
             {
index 4497b3350e98cb137c45505da1db7875417f9a84..c50e874ff88bbb094f17d8bacb714e6dc913b53d 100644 (file)
@@ -17,6 +17,7 @@ closedir
 d-ino
 fcntl-h
 idx
+intprops
 memcmp
 opendirat
 readdir
index 41cf99b02556b380c8995821bc921871b608bf8c..42c8c9ed5357cb9d4b5853193ea771ba7190f639 100644 (file)
@@ -17,6 +17,7 @@ closedir
 d-ino
 fcntl-h
 idx
+intprops
 memcmp
 opendirat
 readdir