X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fquotearg.c;h=d5fbc9e60384ea4b7c0b823535c7d18ea79f8d53;hb=023946e6df1ce4ce382f2385306427413fe46085;hp=9ed8a5fb12f517bbbe2b1827754fc8c051e68915;hpb=8ed25ee69927e755445a4d9b8dcc5d03044c709a;p=gnulib.git diff --git a/lib/quotearg.c b/lib/quotearg.c index 9ed8a5fb1..d5fbc9e60 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -92,15 +92,14 @@ size_t mbrtowc (); #define INT_BITS (sizeof (int) * CHAR_BIT) #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) -/* Undefine to protect against the definition in wctype.h of solaris2.6. */ -# undef ISASCII -# define ISASCII(c) 1 +# define IN_CTYPE_DOMAIN(c) 1 #else -# define ISASCII(c) isascii (c) +# define IN_CTYPE_DOMAIN(c) isascii(c) #endif + /* Undefine to protect against the definition in wctype.h of solaris2.6. */ #undef ISPRINT -#define ISPRINT(c) (ISASCII (c) && isprint (c)) +#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c)) struct quoting_options { @@ -530,12 +529,17 @@ static char * quotearg_n_options (int n, char const *arg, struct quoting_options const *options) { - static unsigned int nslots; - static 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 unsigned int nslots = 1; + struct slotvec { size_t size; char *val; - } *slotvec; + }; + static struct slotvec slotvec0 = {sizeof slot0, slot0}; + static struct slotvec *slotvec = &slotvec0; if (nslots <= n) { @@ -543,6 +547,11 @@ quotearg_n_options (int n, char const *arg, size_t s = n1 * sizeof (struct slotvec); if (! (0 < n1 && n1 == s / sizeof (struct slotvec))) abort (); + if (slotvec == &slotvec0) + { + slotvec = (struct slotvec *) xmalloc (sizeof (struct slotvec)); + *slotvec = slotvec0; + } slotvec = (struct slotvec *) xrealloc (slotvec, s); memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec)); nslots = n; @@ -556,7 +565,7 @@ quotearg_n_options (int n, char const *arg, if (size <= qsize) { slotvec[n].size = size = qsize + 1; - slotvec[n].val = val = xrealloc (val, size); + slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size); quotearg_buffer (val, size, arg, (size_t) -1, options); }