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

« back to all changes in this revision

Viewing changes to lib/regexec.c

  • Committer: Colin Watson
  • Date: 2013-10-30 15:48:33 UTC
  • mfrom: (8.3.5 sid)
  • Revision ID: cjwatson@canonical.com-20131030154833-xdt6e1yfffqom1c4
merge from Debian 8.21-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Extended regular expression matching and search library.
2
 
   Copyright (C) 2002-2012 Free Software Foundation, Inc.
 
2
   Copyright (C) 2002-2013 Free Software Foundation, Inc.
3
3
   This file is part of the GNU C Library.
4
4
   Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
5
5
 
6
 
   This program is free software; you can redistribute it and/or modify
7
 
   it under the terms of the GNU General Public License as published by
8
 
   the Free Software Foundation; either version 3, or (at your option)
9
 
   any later version.
 
6
   The GNU C Library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 3 of the License, or (at your option) any later version.
10
10
 
11
 
   This program is distributed in the hope that it will be useful,
 
11
   The GNU C Library is distributed in the hope that it will be useful,
12
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   General Public License for more details.
15
15
 
16
 
   You should have received a copy of the GNU General Public License along
17
 
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
16
   You should have received a copy of the GNU General Public
 
17
   License along with the GNU C Library; if not, see
 
18
   <http://www.gnu.org/licenses/>.  */
18
19
 
19
20
#include "verify.h"
20
21
#include "intprops.h"
200
201
static bool check_node_accept (const re_match_context_t *mctx,
201
202
                               const re_token_t *node, Idx idx)
202
203
     internal_function;
203
 
static reg_errcode_t extend_buffers (re_match_context_t *mctx)
 
204
static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
204
205
     internal_function;
205
206
 
206
207
/* Entry point for POSIX code.  */
1183
1184
          || (BE (next_char_idx >= mctx->input.valid_len, 0)
1184
1185
              && mctx->input.valid_len < mctx->input.len))
1185
1186
        {
1186
 
          err = extend_buffers (mctx);
 
1187
          err = extend_buffers (mctx, next_char_idx + 1);
1187
1188
          if (BE (err != REG_NOERROR, 0))
1188
1189
            {
1189
1190
              assert (err == REG_ESPACE);
1763
1764
          && mctx->input.valid_len < mctx->input.len))
1764
1765
    {
1765
1766
      reg_errcode_t err;
1766
 
      err = extend_buffers (mctx);
 
1767
      err = extend_buffers (mctx, next_state_log_idx + 1);
1767
1768
      if (BE (err != REG_NOERROR, 0))
1768
1769
        return err;
1769
1770
    }
2820
2821
                  if (bkref_str_off >= mctx->input.len)
2821
2822
                    break;
2822
2823
 
2823
 
                  err = extend_buffers (mctx);
 
2824
                  err = extend_buffers (mctx, bkref_str_off + 1);
2824
2825
                  if (BE (err != REG_NOERROR, 0))
2825
2826
                    return err;
2826
2827
 
3943
3944
                in_collseq = find_collation_sequence_value (pin, elem_len);
3944
3945
            }
3945
3946
          /* match with range expression?  */
 
3947
          /* FIXME: Implement rational ranges here, too.  */
3946
3948
          for (i = 0; i < cset->nranges; ++i)
3947
3949
            if (cset->range_starts[i] <= in_collseq
3948
3950
                && in_collseq <= cset->range_ends[i])
3994
3996
# endif /* _LIBC */
3995
3997
        {
3996
3998
          /* match with range expression?  */
3997
 
#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && defined __STRICT_ANSI__)
3998
 
          wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
3999
 
#else
4000
 
          wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
4001
 
          cmp_buf[2] = wc;
4002
 
#endif
4003
3999
          for (i = 0; i < cset->nranges; ++i)
4004
4000
            {
4005
 
              cmp_buf[0] = cset->range_starts[i];
4006
 
              cmp_buf[4] = cset->range_ends[i];
4007
 
              if (wcscoll (cmp_buf, cmp_buf + 2) <= 0
4008
 
                  && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
 
4001
              if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i])
4009
4002
                {
4010
4003
                  match_len = char_len;
4011
4004
                  goto check_node_accept_bytes_match;
4143
4136
 
4144
4137
static reg_errcode_t
4145
4138
internal_function __attribute_warn_unused_result__
4146
 
extend_buffers (re_match_context_t *mctx)
 
4139
extend_buffers (re_match_context_t *mctx, int min_len)
4147
4140
{
4148
4141
  reg_errcode_t ret;
4149
4142
  re_string_t *pstr = &mctx->input;
4153
4146
          <= pstr->bufs_len, 0))
4154
4147
    return REG_ESPACE;
4155
4148
 
4156
 
  /* Double the lengths of the buffers.  */
4157
 
  ret = re_string_realloc_buffers (pstr, MIN (pstr->len, pstr->bufs_len * 2));
 
4149
  /* Double the lengths of the buffers, but allocate at least MIN_LEN.  */
 
4150
  ret = re_string_realloc_buffers (pstr,
 
4151
                                   MAX (min_len,
 
4152
                                        MIN (pstr->len, pstr->bufs_len * 2)));
4158
4153
  if (BE (ret != REG_NOERROR, 0))
4159
4154
    return ret;
4160
4155