* 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 0c3ea48fe..c68da0df8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-04-06 Paul Eggert <[email protected]> + 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 c53e3f335..1e427e8de 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 4497b3350..c50e874ff 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 41cf99b02..42c8c9ed5 100644 --- a/modules/backupfile +++ b/modules/backupfile @@ -17,6 +17,7 @@ closedir d-ino fcntl-h idx +intprops memcmp opendirat readdir -- 2.27.0
