Regex problem
Kotan
kotan@gmx.at
Thu Oct 28 12:04:00 GMT 2004
Hi!
I tried to use the POSIX regular expression functions under cygwin, and
I only got segmentation faults. My program is working fine under Linux,
but dont run at all with cygwin. Maybe you can give me a hint, whats
wrong or if it is a bug.
Here the source code:
-------------------
#include <sys/types.h>
#include <regex.h>
//#include <pcreposix.h>
#include <stdio.h>
#include <string.h>
#define NMATCH 10
const char s[] = "ssh://user:password@host.com:22";
const char regex[] = "ssh://(([a-z]+)(:(.+))?@)?([a-z.]+)(:([0-9]+))?";
int main(int argc, char *argv[])
{
regex_t *preg;
regmatch_t pmatch[NMATCH];
int i;
char buf[256];
char *p;
preg = NULL;
printf("regcomp...");
if( regcomp( preg, regex, REG_ICASE | REG_EXTENDED ) != 0 )
{
printf("regcomp error!\n");
return 1;
}
printf("regexec...");
if( regexec(preg, s, NMATCH, pmatch, 0) != 0 )
{
printf("regexec failed (no match?)! \n");
return 1;
}
for(i=0; i < NMATCH; i++) {
printf("%d: %d %d\n", i, pmatch[i].rm_so, pmatch[i].rm_eo);
if( pmatch[i].rm_so != -1 )
{
p = s;
memset(buf, 0, sizeof(buf));
strncpy(buf, p + pmatch[i].rm_so, pmatch[i].rm_eo-pmatch[i].rm_so);
printf("%s\n", buf);
}
}
regfree(preg);
return 0;
}
----------
I tried the normal regex POSIX functions and also the Perl-compatiable
Regular Expressions POSIX emulation using the pcreposix header and
library. However the result is always the same:
----
$ ./reex
Segmentation fault (core dumped)
----
Exception: STATUS_ACCESS_VIOLATION at eip=61075334
eax=00000007 ebx=0A0505E0 ecx=00000000 edx=00000000 esi=0022EE30
edi=0A050730
ebp=0022EEB8 esp=0022EE10 program=D:\cygwin\home\Kotan\reex.exe, pid
1696, threa
d main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
0022EEB8 61075334 (00000000, 00403020, 00000003, 0022EEE8)
0022F068 6108DB9F (00000001, 61784348, 0A0500A8, 0022F0C0)
0022F0A8 61005F34 (0022F0C0, 00E50000, 00000408, 7C98C1B0)
0022FF88 6100614B (00000000, 00000000, 00000000, 00000000)
End of stack trace
-------
When I am debugging it with ddd, I find out, that the stack seems to be
manipulated by the regcomp function somehow, that the segmenation fault
happens in cygwin_split_path by accessing adress 0. I also did a strace,
where I dont find anything useful, but I attached it, if you want to
look at it too..
The function regcomp seems always to segfault even if the regex string
is much simpler or even empty.
So any hints, what could be wrong?
regards
Daniel
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: trace
URL: <http://cygwin.com/pipermail/cygwin/attachments/20041028/23be3104/attachment.ksh>
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list