From 4392cab3a01e2df101f3fd269c5b17aa969d0669 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 6 Apr 2021 17:39:31 -0700 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/backupfile.c | 6 ++++-- modules/backup-rename | 1 + modules/backupfile | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c3ea48fe8..c68da0df85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-04-06 Paul Eggert + 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): diff --git a/lib/backupfile.c b/lib/backupfile.c index c53e3f335a..1e427e8def 100644 --- a/lib/backupfile.c +++ b/lib/backupfile.c @@ -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) { diff --git a/modules/backup-rename b/modules/backup-rename index 4497b3350e..c50e874ff8 100644 --- a/modules/backup-rename +++ b/modules/backup-rename @@ -17,6 +17,7 @@ closedir d-ino fcntl-h idx +intprops memcmp opendirat readdir diff --git a/modules/backupfile b/modules/backupfile index 41cf99b025..42c8c9ed53 100644 --- a/modules/backupfile +++ b/modules/backupfile @@ -17,6 +17,7 @@ closedir d-ino fcntl-h idx +intprops memcmp opendirat readdir -- 2.39.5