* [PATCH] xalloc: delay setting size until success
@ 2021-04-01 8:05 Paul Eggert
0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2021-04-01 8:05 UTC (permalink / raw)
To: bug-gnulib; +Cc: Paul Eggert
* lib/xalloc.h (x2nrealloc): Don’t change *PN until after xrealloc
succeeds, in case xalloc_die or one of its callees or longjmp
targets uses *PN. Similar code in xpalloc already does this.
---
ChangeLog | 7 +++++++
lib/xalloc.h | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 78bf3a5a7..784409dba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-03-31 Paul Eggert <eggert@cs.ucla.edu>
+
+ xalloc: delay setting size until success
+ * lib/xalloc.h (x2nrealloc): Don’t change *PN until after xrealloc
+ succeeds, in case xalloc_die or one of its callees or longjmp
+ targets uses *PN. Similar code in xpalloc already does this.
+
2021-03-28 Paul Eggert <eggert@cs.ucla.edu>
xalloc: new function xpalloc, from dfa
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 76d83c63c..5633fdf3c 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -206,8 +206,9 @@ x2nrealloc (void *p, size_t *pn, size_t s)
n += n / 2 + 1;
}
+ p = xrealloc (p, n * s);
*pn = n;
- return xrealloc (p, n * s);
+ return p;
}
/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
--
2.30.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-01 8:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 8:05 [PATCH] xalloc: delay setting size until success Paul Eggert
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).