Blame posix/bug-regex33.c

Packit 6c4009
/* Test re_search with multi-byte characters in EUC-JP.
Packit 6c4009
   Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Stanislav Brabec <sbrabec@suse.cz>, 2012.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#define _GNU_SOURCE 1
Packit 6c4009
#include <locale.h>
Packit 6c4009
#include <regex.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  struct re_pattern_buffer r;
Packit 6c4009
  struct re_registers s;
Packit 6c4009
  int e, rc = 0;
Packit 6c4009
  if (setlocale (LC_CTYPE, "ja_JP.EUC-JP") == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("setlocale failed");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  memset (&r, 0, sizeof (r));
Packit 6c4009
  memset (&s, 0, sizeof (s));
Packit 6c4009
Packit 6c4009
  /* The bug cannot be reproduced without initialized fastmap (it is SBC_MAX
Packit 6c4009
     value from regex_internal.h).  */
Packit 6c4009
  r.fastmap = malloc (UCHAR_MAX + 1);
Packit 6c4009
Packit 6c4009
                     /* 圭 */
Packit 6c4009
  re_compile_pattern ("\xb7\xbd", 2, &r);
Packit 6c4009
Packit 6c4009
                /* aaaaa件a新処, \xb7\xbd constitutes a false match */
Packit 6c4009
  e = re_search (&r, "\x61\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
Packit 6c4009
                 12, 0, 12, &s);
Packit 6c4009
  if (e != -1)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.1: false match or error: re_search() returned %d, should return -1\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* aaaa件a新処, \xb7\xbd constitutes a false match,
Packit 6c4009
                 * this is a reproducer of BZ #13637 */
Packit 6c4009
  e = re_search (&r, "\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
Packit 6c4009
                 11, 0, 11, &s);
Packit 6c4009
  if (e != -1)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.2: false match or error: re_search() returned %d, should return -1\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* aaa件a新処, \xb7\xbd constitutes a false match,
Packit 6c4009
                 * this is a reproducer of BZ #13637 */
Packit 6c4009
  e = re_search (&r, "\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
Packit 6c4009
                 10, 0, 10, &s);
Packit 6c4009
  if (e != -1)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.3: false match or error: re_search() returned %d, should return -1\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* aa件a新処, \xb7\xbd constitutes a false match */
Packit 6c4009
  e = re_search (&r, "\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
Packit 6c4009
                 9, 0, 9, &s);
Packit 6c4009
  if (e != -1)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.4: false match or error: re_search() returned %d, should return -1\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* a件a新処, \xb7\xbd constitutes a false match */
Packit 6c4009
  e = re_search (&r, "\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
Packit 6c4009
                 8, 0, 8, &s);
Packit 6c4009
  if (e != -1)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.5: false match or error: re_search() returned %d, should return -1\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* 新処圭新処, \xb7\xbd here really matches 圭, but second occurrence is a false match,
Packit 6c4009
                 * this is a reproducer of bug-regex25 and BZ #13637 */
Packit 6c4009
  e = re_search (&r, "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7\xbd\xe8",
Packit 6c4009
                 10, 0, 10, &s);
Packit 6c4009
  if (e != 4)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.6: no match or false match: re_search() returned %d, should return 4\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
                /* 新処圭新, \xb7\xbd here really matches 圭,
Packit 6c4009
                 * this is a reproducer of bug-regex25 */
Packit 6c4009
  e = re_search (&r, "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7",
Packit 6c4009
                 10, 0, 10, &s);
Packit 6c4009
  if (e != 4)
Packit 6c4009
    {
Packit 6c4009
      printf ("bug-regex33.7: no match or false match: re_search() returned %d, should return 4\n", e);
Packit 6c4009
      rc = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return rc;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"