From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH 2/3] backupfile: less-aggressive buffer growth
Date: Tue, 6 Apr 2021 17:52:10 -0700 [thread overview]
Message-ID: <20210407005211.240077-2-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20210407005211.240077-1-eggert@cs.ucla.edu>
* 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 <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):
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
next prev parent reply other threads:[~2021-04-07 0:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-07 0:52 [PATCH 1/3] xalloc-oversized: export xalloc_count_t Paul Eggert
2021-04-07 0:52 ` Paul Eggert [this message]
2021-04-07 0:52 ` [PATCH 3/3] group-member: minor tweak to omit a * Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210407005211.240077-2-eggert@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).