~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/regex_internal.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- buffer-read-only: t -*- vi: set ro: */
2
 
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3
1
/* Extended regular expression matching and search library.
4
 
   Copyright (C) 2002-2011 Free Software Foundation, Inc.
 
2
   Copyright (C) 2002-2012 Free Software Foundation, Inc.
5
3
   This file is part of the GNU C Library.
6
4
   Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
7
5
 
16
14
   GNU General Public License for more details.
17
15
 
18
16
   You should have received a copy of the GNU General Public License along
19
 
   with this program; if not, write to the Free Software Foundation,
20
 
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
 
17
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
21
18
 
22
19
#include "verify.h"
23
20
#include "intprops.h"
138
135
    {
139
136
      wint_t *new_wcs;
140
137
 
141
 
      /* Avoid overflow.  */
142
 
      size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
143
 
      if (BE (SIZE_MAX / max_object_size < new_buf_len, 0))
 
138
      /* Avoid overflow in realloc.  */
 
139
      const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
 
140
      if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0))
144
141
        return REG_ESPACE;
145
142
 
146
143
      new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
240
237
      else
241
238
        p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
242
239
      mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
243
 
      if (BE (mbclen == (size_t) -2, 0))
244
 
        {
245
 
          /* The buffer doesn't have enough space, finish to build.  */
246
 
          pstr->cur_state = prev_st;
247
 
          break;
248
 
        }
249
 
      else if (BE (mbclen == (size_t) -1 || mbclen == 0, 0))
 
240
      if (BE (mbclen == (size_t) -1 || mbclen == 0
 
241
              || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0))
250
242
        {
251
243
          /* We treat these cases as a singlebyte character.  */
252
244
          mbclen = 1;
255
247
            wc = pstr->trans[wc];
256
248
          pstr->cur_state = prev_st;
257
249
        }
 
250
      else if (BE (mbclen == (size_t) -2, 0))
 
251
        {
 
252
          /* The buffer doesn't have enough space, finish to build.  */
 
253
          pstr->cur_state = prev_st;
 
254
          break;
 
255
        }
258
256
 
259
257
      /* Write wide character and padding.  */
260
258
      pstr->wcs[byte_idx++] = wc;
337
335
              for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
338
336
                pstr->wcs[byte_idx++] = WEOF;
339
337
            }
340
 
          else if (mbclen == (size_t) -1 || mbclen == 0)
 
338
          else if (mbclen == (size_t) -1 || mbclen == 0
 
339
                   || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
341
340
            {
342
 
              /* It is an invalid character or '\0'.  Just use the byte.  */
 
341
              /* It is an invalid character, an incomplete character
 
342
                 at the end of the string, or '\0'.  Just use the byte.  */
343
343
              int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
344
344
              pstr->mbs[byte_idx] = ch;
345
345
              /* And also cast it to wide char.  */
452
452
            for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
453
453
              pstr->wcs[byte_idx++] = WEOF;
454
454
          }
455
 
        else if (mbclen == (size_t) -1 || mbclen == 0)
 
455
        else if (mbclen == (size_t) -1 || mbclen == 0
 
456
                 || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
456
457
          {
457
458
            /* It is an invalid character or '\0'.  Just use the byte.  */
458
459
            int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
499
500
       rawbuf_idx < new_raw_idx;)
500
501
    {
501
502
      wchar_t wc2;
502
 
      Idx remain_len;
503
 
      remain_len = pstr->len - rawbuf_idx;
 
503
      Idx remain_len = pstr->raw_len - rawbuf_idx;
504
504
      prev_st = pstr->cur_state;
505
505
      mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
506
506
                          remain_len, &pstr->cur_state);
736
736
                          mbstate_t cur_state;
737
737
                          wchar_t wc2;
738
738
                          Idx mlen = raw + pstr->len - p;
 
739
                          unsigned char buf[6];
739
740
                          size_t mbclen;
740
741
 
741
 
#if 0 /* dead code: buf is set but never used */
742
 
                          unsigned char buf[6];
 
742
                          const unsigned char *pp = p;
743
743
                          if (BE (pstr->trans != NULL, 0))
744
744
                            {
745
745
                              int i = mlen < 6 ? mlen : 6;
746
746
                              while (--i >= 0)
747
747
                                buf[i] = pstr->trans[p[i]];
 
748
                              pp = buf;
748
749
                            }
749
 
#endif
750
750
                          /* XXX Don't use mbrtowc, we know which conversion
751
751
                             to use (UTF-8 -> UCS4).  */
752
752
                          memset (&cur_state, 0, sizeof (cur_state));
753
 
                          mbclen = __mbrtowc (&wc2, (const char *) p, mlen,
 
753
                          mbclen = __mbrtowc (&wc2, (const char *) pp, mlen,
754
754
                                              &cur_state);
755
755
                          if (raw + offset - p <= mbclen
756
756
                              && mbclen < (size_t) -2)
872
872
}
873
873
 
874
874
static unsigned char
875
 
internal_function __attribute ((pure))
 
875
internal_function
876
876
re_string_fetch_byte_case (re_string_t *pstr)
877
877
{
878
878
  if (BE (!pstr->mbs_allocated, 1))
1419
1419
      Idx *new_nexts, *new_indices;
1420
1420
      re_node_set *new_edests, *new_eclosures;
1421
1421
      re_token_t *new_nodes;
1422
 
      size_t max_object_size =
1423
 
        MAX (sizeof (re_token_t),
1424
 
             MAX (sizeof (re_node_set),
1425
 
                  sizeof (Idx)));
1426
1422
 
1427
 
      /* Avoid overflows.  */
1428
 
      if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0))
 
1423
      /* Avoid overflows in realloc.  */
 
1424
      const size_t max_object_size = MAX (sizeof (re_token_t),
 
1425
                                          MAX (sizeof (re_node_set),
 
1426
                                               sizeof (Idx)));
 
1427
      if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0))
1429
1428
        return REG_MISSING;
1430
1429
 
1431
1430
      new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
1557
1556
          && re_node_set_compare (state->entrance_nodes, nodes))
1558
1557
        return state;
1559
1558
    }
1560
 
  /* There are no appropriate state in `dfa', create the new one.  */
 
1559
  /* There are no appropriate state in 'dfa', create the new one.  */
1561
1560
  new_state = create_cd_newstate (dfa, nodes, context, hash);
1562
1561
  if (BE (new_state == NULL, 0))
1563
1562
    *err = REG_ESPACE;
1586
1585
    {
1587
1586
      Idx elem = newstate->nodes.elems[i];
1588
1587
      if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
1589
 
        if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0))
 
1588
        if (! re_node_set_insert_last (&newstate->non_eps_nodes, elem))
1590
1589
          return REG_ESPACE;
1591
1590
    }
1592
1591
 
1621
1620
  re_free (state);
1622
1621
}
1623
1622
 
1624
 
/* Create the new state which is independ of contexts.
 
1623
/* Create the new state which is independent of contexts.
1625
1624
   Return the new state if succeeded, otherwise return NULL.  */
1626
1625
 
1627
1626
static re_dfastate_t *