A patch for regex.c
H . J . Lu
hjl@valinux.com
Wed Mar 8 14:03:00 GMT 2000
I am enclosing testcase here. According to regex.h,
/* If this bit is set, either \{...\} or {...} defines an
interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
When RE_INTERVALS is set and RE_NO_BK_BRACES is not set, \{...\}
define an interval.
Did I miss something?
H.J.
----
#include <stdio.h>
#include <regex.h>
int
main ()
{
static struct re_pattern_buffer regex;
const char *s;
re_set_syntax (RE_SYNTAX_POSIX_EGREP);
printf ("syntax: RE_NO_BK_BRACES: %d, RE_INTERVALS: %d\n",
re_syntax_options & RE_NO_BK_BRACES,
re_syntax_options & RE_INTERVALS);
s = re_compile_pattern ("\\{1", 2, ®ex);
printf ("\\{1: %s\n", s ? "FAIL" : "PASS");
s = re_compile_pattern ("{1", 2, ®ex);
printf ("{1: %s\n", s ? "PASS" : "FAIL");
re_syntax_options &= ~RE_NO_BK_BRACES;
printf ("syntax: RE_NO_BK_BRACES: %d, RE_INTERVALS: %d\n",
re_syntax_options & RE_NO_BK_BRACES,
re_syntax_options & RE_INTERVALS);
s = re_compile_pattern ("\\{1", 2, ®ex);
printf ("\\{1: %s\n", s ? "PASS" : "FAIL");
s = re_compile_pattern ("{1", 2, ®ex);
printf ("{1: %s\n", s ? "FAIL" : "PASS");
return 0;
}
----
--
H.J. Lu (hjl@gnu.org)
---
2000-03-08 H.J. Lu <hjl@gnu.org>
* posix/regex.c (regex_compile): Correctly handle "\{" when
the RE_INTERVALS is set and the RE_NO_BK_BRACES bit is not set.
Index: posix/regex.c
===================================================================
RCS file: /work/cvs/gnu/glibc-2.1/posix/regex.c,v
retrieving revision 1.1.1.32
diff -u -p -r1.1.1.32 regex.c
--- posix/regex.c 2000/02/24 18:05:37 1.1.1.32
+++ posix/regex.c 2000/03/08 21:26:58
@@ -2604,8 +2604,7 @@ regex_compile (pattern, size, syntax, bu
if (!(syntax & RE_INTERVALS)
/* If we're at `\{' and it's not the open-interval
operator. */
- || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
- || (p - 2 == pattern && p == pend))
+ || (syntax & RE_NO_BK_BRACES))
goto normal_backslash;
handle_interval:
More information about the Libc-hacker
mailing list