This is the mail archive of the
glibc-bugs-regex@sourceware.org
mailing list for the glibc project.
[Bug regex/11783] New: Wrong result with RE_NO_SUB, $ and {n}
- From: "bonzini at gnu dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs-regex at sources dot redhat dot com
- Date: 2 Jul 2010 08:24:55 -0000
- Subject: [Bug regex/11783] New: Wrong result with RE_NO_SUB, $ and {n}
- Reply-to: sourceware-bugzilla at sourceware dot org
The following program emits
RE_NO_SUB 1: matched at 4
~RE_NO_SUB 1: not matched
RE_NO_SUB 2: matched at 4
~RE_NO_SUB 2: not matched
RE_NO_SUB 3: matched at 4
~RE_NO_SUB 3: not matched
RE_NO_SUB 4: not matched
~RE_NO_SUB 4: not matched
so matching regexes 1 to 3 is buggy.
#define _GNU_SOURCE 1
#include <regex.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int test (const char *regex, const char *text, int syntax, const char *name)
{
const char *error;
regex_t pat;
int ret;
re_set_syntax (RE_SYNTAX_POSIX_EXTENDED | syntax);
memset (&pat, 0, sizeof(pat));
error = re_compile_pattern (regex, strlen(regex), &pat);
ret = re_search (&pat, text, strlen (text), 0, strlen (text), NULL);
if (ret > -1)
printf ("%s: matched at %d\n", name, ret);
else
printf ("%s: not matched\n", name);
regfree (&pat);
}
int main()
{
const char regex1[] = "([0-9]+([^0-9]+|$)){2}";
const char regex2[] = "([0-9][0-9]*([^0-9][^0-9]*|$)){2}";
const char regex3[] = "([0-9]+([^0-9]+|$)){3}";
const char regex4[] = "([0-9]+([^0-9]+|$))([0-9]+([^0-9]+|$))";
const char text[] = "xxx 888";
test (regex1, text, RE_NO_SUB, "RE_NO_SUB 1");
test (regex1, text, 0, "~RE_NO_SUB 1");
test (regex2, text, RE_NO_SUB, "RE_NO_SUB 2");
test (regex2, text, 0, "~RE_NO_SUB 2");
test (regex3, text, RE_NO_SUB, "RE_NO_SUB 3");
test (regex3, text, 0, "~RE_NO_SUB 3");
test (regex4, text, RE_NO_SUB, "RE_NO_SUB 4");
test (regex4, text, 0, "~RE_NO_SUB 4");
}
--
Summary: Wrong result with RE_NO_SUB, $ and {n}
Product: glibc
Version: 2.12
Status: NEW
Severity: normal
Priority: P2
Component: regex
AssignedTo: drepper at redhat dot com
ReportedBy: bonzini at gnu dot org
CC: glibc-bugs-regex at sources dot redhat dot com,glibc-
bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=11783
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.