* 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 <egg...@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 <egg...@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