/[bison]/bison/lib/quotearg.c
ViewVC logotype

Diff of /bison/lib/quotearg.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.1 by akim, Thu Sep 27 14:25:57 2001 UTC revision 1.2.2.2 by akim, Fri Nov 30 14:04:22 2001 UTC
# Line 44  Line 44 
44  #ifndef CHAR_BIT  #ifndef CHAR_BIT
45  # define CHAR_BIT 8  # define CHAR_BIT 8
46  #endif  #endif
47    #ifndef SIZE_MAX
48    # define SIZE_MAX ((size_t) -1)
49    #endif
50  #ifndef UCHAR_MAX  #ifndef UCHAR_MAX
51  # define UCHAR_MAX ((unsigned char) -1)  # define UCHAR_MAX ((unsigned char) -1)
52  #endif  #endif
53    #ifndef UINT_MAX
54    # define UINT_MAX ((unsigned int) -1)
55    #endif
56    
57  #if HAVE_C_BACKSLASH_A  #if HAVE_C_BACKSLASH_A
58  # define ALERT_CHAR '\a'  # define ALERT_CHAR '\a'
# Line 539  quotearg_n_options (int n, char const *a Line 545  quotearg_n_options (int n, char const *a
545       one small component of a "memory exhausted" message in slot 0.  */       one small component of a "memory exhausted" message in slot 0.  */
546    static char slot0[256];    static char slot0[256];
547    static unsigned int nslots = 1;    static unsigned int nslots = 1;
548      unsigned int n0 = n;
549    struct slotvec    struct slotvec
550      {      {
551        size_t size;        size_t size;
# Line 547  quotearg_n_options (int n, char const *a Line 554  quotearg_n_options (int n, char const *a
554    static struct slotvec slotvec0 = {sizeof slot0, slot0};    static struct slotvec slotvec0 = {sizeof slot0, slot0};
555    static struct slotvec *slotvec = &slotvec0;    static struct slotvec *slotvec = &slotvec0;
556    
557    if (nslots <= n)    if (n < 0)
558        abort ();
559    
560      if (nslots <= n0)
561      {      {
562        int n1 = n + 1;        unsigned int n1 = n0 + 1;
563        size_t s = n1 * sizeof (struct slotvec);        size_t s = n1 * sizeof *slotvec;
564        if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))  
565          abort ();        if (SIZE_MAX / UINT_MAX <= sizeof *slotvec
566              && n1 != s / sizeof *slotvec)
567            xalloc_die ();
568    
569        if (slotvec == &slotvec0)        if (slotvec == &slotvec0)
570          {          {
571            slotvec = (struct slotvec *) xmalloc (sizeof (struct slotvec));            slotvec = (struct slotvec *) xmalloc (sizeof *slotvec);
572            *slotvec = slotvec0;            *slotvec = slotvec0;
573          }          }
574        slotvec = (struct slotvec *) xrealloc (slotvec, s);        slotvec = (struct slotvec *) xrealloc (slotvec, s);
575        memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));        memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);
576        nslots = n;        nslots = n1;
577      }      }
578    
579    {    {
# Line 580  quotearg_n_options (int n, char const *a Line 593  quotearg_n_options (int n, char const *a
593  }  }
594    
595  char *  char *
596  quotearg_n (unsigned int n, char const *arg)  quotearg_n (int n, char const *arg)
597  {  {
598    return quotearg_n_options (n, arg, &default_quoting_options);    return quotearg_n_options (n, arg, &default_quoting_options);
599  }  }
# Line 592  quotearg (char const *arg) Line 605  quotearg (char const *arg)
605  }  }
606    
607  char *  char *
608  quotearg_n_style (unsigned int n, enum quoting_style s, char const *arg)  quotearg_n_style (int n, enum quoting_style s, char const *arg)
609  {  {
610    struct quoting_options o;    struct quoting_options o;
611    o.style = s;    o.style = s;

Legend:
Removed from v.1.2.2.1  
changed lines
  Added in v.1.2.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26