tst-preadwrite tst-preadwrite64 test-vfork regexbug1 \
tst-getlogin tst-mmap tst-getaddrinfo tst-truncate \
tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \
- tst-chmod bug-regex1
+ tst-chmod bug-regex1 bug-regex2
ifeq (yes,$(build-shared))
test-srcs := globtest
tests += wordexp-test tst-exec tst-spawn
# Run a test on the header files we use.
# XXX Please note that for now we ignore the result of this test.
-tests: $(objpfx)annexc.out
+tests: $(objpfx)annexc.out $(objpfx)bug-regex2-mem
$(objpfx)annexc.out: $(objpfx)annexc
-$(dir $<)$(notdir $<) '$(CC)' \
'-I../include -I.. $(+sysdep-includes) $(sysincludes)' > $@
$(objpfx)annexc: annexc.c
$(native-compile)
+
+bug-regex2-ENV = MALLOC_TRACE=$(objpfx)bug-regex2.mtrace
+
+$(objpfx)bug-regex2-mem: $(objpfx)bug-regex2.out
+ $(common-objpfx)malloc/mtrace $(objpfx)bug-regex2.mtrace > $@
--- /dev/null
+/* Test for memory handling in regex.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <sys/types.h>
+#include <mcheck.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static const char text[] = "This is a test; this is a test";
+
+int
+main (void)
+{
+ regex_t re;
+ regmatch_t rm[2];
+ int n;
+
+ mtrace ();
+
+ n = regcomp (&re, "a test", REG_EXTENDED);
+ if (n != 0)
+ {
+ char buf[500];
+ regerror (n, &re, buf, sizeof (buf));
+ printf ("regcomp failed: %s\n", buf);
+ exit (1);
+ }
+
+ for (n = 0; n < 20; ++n)
+ regexec (&re, text, 2, rm, 0);
+
+ regfree (&re);
+
+ return 0;
+}
static size_t convert_mbs_to_wcs (CHAR_TYPE *dest, const unsigned char* src,
size_t len, int *offset_buffer,
- int *is_binary);
+ char *is_binary);
static size_t
convert_mbs_to_wcs (dest, src, len, offset_buffer, is_binary)
CHAR_TYPE *dest;
= {0, 3, 4, 6}
*/
int *offset_buffer;
- int *is_binary;
+ char *is_binary;
{
wchar_t *pdest = dest;
const unsigned char *psrc = src;
/* offset buffer for optimizatoin. See convert_mbs_to_wc. */
int *mbs_offset = NULL;
/* It hold whether each wchar_t is binary data or not. */
- int *is_binary = NULL;
+ char *is_binary = NULL;
/* A flag whether exactn is handling binary data or not. */
- int is_exactn_bin = FALSE;
+ char is_exactn_bin = FALSE;
#endif /* MBS_SUPPORT */
/* A random temporary spot in PATTERN. */
/* Initialize the wchar_t PATTERN and offset_buffer. */
p = pend = pattern = TALLOC(csize, CHAR_TYPE);
mbs_offset = TALLOC(csize + 1, int);
- is_binary = TALLOC(csize + 1, int);
+ is_binary = TALLOC(csize + 1, char);
if (pattern == NULL || mbs_offset == NULL || is_binary == NULL)
{
if (pattern) free(pattern);
FREE_VAR (string2); \
FREE_VAR (mbs_offset1); \
FREE_VAR (mbs_offset2); \
- FREE_VAR (is_binary1); \
- FREE_VAR (is_binary2); \
} while (0)
# else /* not MBS_SUPPORT */
# define FREE_VARIABLES() \
} while (0)
# endif /* MBS_SUPPORT */
#else
+# define FREE_VAR(var) if (var) free (var); var = NULL
# ifdef MBS_SUPPORT
# define FREE_VARIABLES() \
do { \
- if (string1) free (string1); \
- if (string2) free (string2); \
- if (mbs_offset1) free (mbs_offset1); \
- if (mbs_offset2) free (mbs_offset2); \
- if (is_binary1) free (is_binary1); \
- if (is_binary2) free (is_binary2); \
+ FREE_VAR (string1); \
+ FREE_VAR (string2); \
+ FREE_VAR (mbs_offset1); \
+ FREE_VAR (mbs_offset2); \
} while (0)
-# eles
+# else
# define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
# endif /* MBS_SUPPORT */
#endif /* not MATCH_MAY_ALLOCATE */
/* offset buffer for optimizatoin. See convert_mbs_to_wc. */
int *mbs_offset1 = NULL, *mbs_offset2 = NULL;
/* They hold whether each wchar_t is binary data or not. */
- int *is_binary1 = NULL, *is_binary2 = NULL;
+ char *is_binary = NULL;
#endif /* MBS_SUPPORT */
/* Just past the end of the corresponding string. */
fill them with converted string. */
if (csize1 != 0)
{
- string1 = TALLOC (csize1 + 1, CHAR_TYPE);
- mbs_offset1 = TALLOC (csize1 + 1, int);
- is_binary1 = TALLOC (csize1 + 1, int);
- if (!string1 || !mbs_offset1 || !is_binary1)
+ string1 = REGEX_TALLOC (csize1 + 1, CHAR_TYPE);
+ mbs_offset1 = REGEX_TALLOC (csize1 + 1, int);
+ is_binary = REGEX_TALLOC (csize1 + 1, char);
+ if (!string1 || !mbs_offset1 || !is_binary)
{
- if (string1) free(string1);
- if (mbs_offset1) free(mbs_offset1);
- if (is_binary1) free(is_binary1);
+ FREE_VAR (string1);
+ FREE_VAR (mbs_offset1);
+ FREE_VAR (is_binary);
return -2;
}
size1 = convert_mbs_to_wcs(string1, cstring1, csize1,
- mbs_offset1, is_binary1);
+ mbs_offset1, is_binary);
string1[size1] = L'\0'; /* for a sentinel */
+ FREE_VAR (is_binary);
}
if (csize2 != 0)
{
string2 = REGEX_TALLOC (csize2 + 1, CHAR_TYPE);
mbs_offset2 = REGEX_TALLOC (csize2 + 1, int);
- is_binary2 = TALLOC (csize2 + 1, int);
- if (!string2 || !mbs_offset2 || !is_binary2)
+ is_binary = REGEX_TALLOC (csize2 + 1, char);
+ if (!string2 || !mbs_offset2 || !is_binary)
{
- if (string1) free(string1);
- if (mbs_offset1) free(mbs_offset1);
- if (is_binary1) free(is_binary1);
- if (string2) free(string2);
- if (mbs_offset2) free(mbs_offset2);
- if (is_binary2) free(is_binary2);
+ FREE_VAR (string1);
+ FREE_VAR (mbs_offset1);
+ FREE_VAR (string2);
+ FREE_VAR (mbs_offset2);
+ FREE_VAR (is_binary);
return -2;
}
size2 = convert_mbs_to_wcs(string2, cstring2, csize2,
- mbs_offset2, is_binary2);
+ mbs_offset2, is_binary);
string2[size2] = L'\0'; /* for a sentinel */
+ FREE_VAR (is_binary);
}
/* We need to cast pattern to (wchar_t*), because we casted this compiled