* lib/quotearg.c: Include xwalloc.h instead of xalloc.h. (clone_quoting_options, quotearg_alloc_mem, nslots) (quotearg_n_options): Use ptrdiff_t rather than size_t, and xwalloc.h rather than xalloc.h functions. * modules/quotearg (Depends-on): Remove xalloc, add xwalloc. --- ChangeLog | 7 +++++++ lib/quotearg.c | 23 +++++++++++------------ modules/quotearg | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 8714e51..460a383 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2017-06-04 Paul Eggert <[email protected]> + quotearg: use xwalloc rather than xalloc + * lib/quotearg.c: Include xwalloc.h instead of xalloc.h. + (clone_quoting_options, quotearg_alloc_mem, nslots) + (quotearg_n_options): Use ptrdiff_t rather than size_t, + and xwalloc.h rather than xalloc.h functions. + * modules/quotearg (Depends-on): Remove xalloc, add xwalloc. + propername: use xwalloc rather than xalloc * lib/propername.c: Include xwalloc.h rather than xalloc.h. (proper_name, proper_name_utf8): Use xwalloc.h rather than diff --git a/lib/quotearg.c b/lib/quotearg.c index 06172c1..a7a26e7 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -30,7 +30,7 @@ #include "quote.h" #include "minmax.h" -#include "xalloc.h" +#include "xwalloc.h" #include "c-strcaseeq.h" #include "localcharset.h" @@ -122,8 +122,8 @@ struct quoting_options * clone_quoting_options (struct quoting_options *o) { int e = errno; - struct quoting_options *p = xmemdup (o ? o : &default_quoting_options, - sizeof *o); + struct quoting_options *p = xwmemdup (o ? o : &default_quoting_options, + sizeof *o); errno = e; return p; } @@ -820,7 +820,7 @@ quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size, flags, p->quote_these_too, p->left_quote, p->right_quote) + 1; - char *buf = xcharalloc (bufsize); + char *buf = xwmalloc (bufsize); quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags, p->quote_these_too, p->left_quote, p->right_quote); @@ -840,7 +840,7 @@ struct slotvec /* Preallocate a slot 0 buffer, so that the caller can always quote one small component of a "memory exhausted" message in slot 0. */ static char slot0[256]; -static int nslots = 1; +static ptrdiff_t nslots = 1; static struct slotvec slotvec0 = {sizeof slot0, slot0}; static struct slotvec *slotvec = &slotvec0; @@ -887,15 +887,14 @@ quotearg_n_options (int n, char const *arg, size_t argsize, if (nslots <= n) { bool preallocated = (sv == &slotvec0); + int nslots0 = nslots; - if (MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) <= n) - xalloc_die (); - - slotvec = sv = xrealloc (preallocated ? NULL : sv, (n + 1) * sizeof *sv); + slotvec = sv = xwgrowalloc (preallocated ? NULL : sv, &nslots, + n - nslots + 1, MIN (INT_MAX, PTRDIFF_MAX), + sizeof *sv); if (preallocated) *sv = slotvec0; - memset (sv + nslots, 0, (n + 1 - nslots) * sizeof *sv); - nslots = n + 1; + memset (sv + nslots, 0, (nslots - nslots0) * sizeof *sv); } { @@ -914,7 +913,7 @@ quotearg_n_options (int n, char const *arg, size_t argsize, sv[n].size = size = qsize + 1; if (val != slot0) free (val); - sv[n].val = val = xcharalloc (size); + sv[n].val = val = xwmalloc (size); quotearg_buffer_restyled (val, size, arg, argsize, options->style, flags, options->quote_these_too, options->left_quote, diff --git a/modules/quotearg b/modules/quotearg index 109a16d..bc5358c 100644 --- a/modules/quotearg +++ b/modules/quotearg @@ -23,7 +23,7 @@ stdbool stdint wchar wctype-h -xalloc +xwalloc configure.ac: gl_QUOTEARG -- 2.9.4
