From: Paul Eggert Date: Wed, 29 Oct 2003 17:33:05 +0000 (+0000) Subject: (quotearg_n_options): Use free/xmalloc rather than xrealloc. X-Git-Tag: cvs-readonly~4361 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=3105da51f87d99c7c821790aebc1af265d3a51a4;p=gnulib.git (quotearg_n_options): Use free/xmalloc rather than xrealloc. Use a simpler test for size overflow. Don't use xalloc_oversized because unsigned int might be wider than size_t (!); this suggests that we should switch from unsigned int to size_t for slot numbers. --- diff --git a/lib/quotearg.c b/lib/quotearg.c index bffa14b7a..83b62fa20 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -538,10 +538,8 @@ quotearg_n_options (int n, char const *arg, size_t argsize, if (nslots <= n0) { unsigned int n1 = n0 + 1; - size_t s = n1 * sizeof *slotvec; - if (SIZE_MAX / UINT_MAX <= sizeof *slotvec - && n1 != s / sizeof *slotvec) + if (SIZE_MAX / sizeof *slotvec < n1) xalloc_die (); if (slotvec == &slotvec0) @@ -549,7 +547,7 @@ quotearg_n_options (int n, char const *arg, size_t argsize, slotvec = xmalloc (sizeof *slotvec); *slotvec = slotvec0; } - slotvec = xrealloc (slotvec, s); + slotvec = xrealloc (slotvec, n1 * sizeof *slotvec); memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec); nslots = n1; } @@ -562,7 +560,9 @@ quotearg_n_options (int n, char const *arg, size_t argsize, if (size <= qsize) { slotvec[n].size = size = qsize + 1; - slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size); + if (val != slot0) + free (val); + slotvec[n].val = val = xmalloc (size); quotearg_buffer (val, size, arg, argsize, options); }