[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
regex.h problem
From: |
Dana Lacoste |
Subject: |
regex.h problem |
Date: |
Wed, 6 Feb 2002 08:31:08 -0800 |
There seems to be a bug in regex.h when it comes to handling
escaped single quotes (talk about obscure :)
specifically, the test program below fails on glibc 2.2.3
but passes on 2.1.2 without a problem.
I'm currently trying to see if I can get other glibc's tested
(FreeBSD 4.5's libc passes, but I know that's not useful :)
(There's sample code attached at the bottom of the message)
The specific situation : reading a string that occasionally
has a single quote in front of it, so trying to pattern match
on an optional single quote.
This is a bug because if you switch the ' character with
any other character (say, an X) it works fine. It also works
if the ' character is not escaped, and if the ' character
is escaped inside a set of \( \) parentheses.
To summarize :
"^\\(\\'\\)?STUFF" passes
"^'?STUFF" passes
"^\\X?STUFF" passes
"^\\'?STUFF" fails
Using gcc 2.95.3, glibc 2.2.3
Dana Lacoste - Linux Developer
Peregrine Systems - Ottawa, Canada
-- begin sample/test code --
#include <stdio.h>
#include <regex.h>
main(int argc,char **argv)
{
const char *txt = "^\\'?STUFF";
regex_t reg;
int err_code = regcomp(®,txt, REG_EXTENDED | REG_NOSUB);
if(err_code != 0)
{
size_t errbuf_size = regerror(err_code,®,NULL,0);
char *errbuf = new char[errbuf_size];
regerror(err_code,®,errbuf,errbuf_size);
printf("Error = (%d)%s (%s)\n",err_code,errbuf,txt);
}
else
{
size_t errbuf_size = regerror(err_code,®,NULL,0);
char *errbuf = new char[errbuf_size];
regerror(err_code,®,errbuf,errbuf_size);
printf("Ok = (%s)\n",txt);
}
}
- regex.h problem,
Dana Lacoste <=