UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » Segmentation fault(core dumped)

#1 2007-08-11 08:43 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

char matches[999];
	regexec("#<wsse\:BinarySecurityToken Id=\"Compact1\">(.*)</wsse:BinarySecurityToken>(.*)<wst\:BinarySecret>(.*)</wst\:BinarySecret>(.*)<wsse\:BinarySecurityToken Id=\"Compact2\">(.*)</wsse:BinarySecurityToken>(.*)<wsse\:BinarySecurityToken Id=\"Compact3\">(.*)</wsse:BinarySecurityToken>#",dtest,999,matches);

Offline

#2 2007-08-11 09:58 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

Read the regexec manpage and turn on compiler warnings.

Offline

#3 2007-08-12 11:15 AM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

I red the man pages .. I mean, the pages about regexec on the GNU website .. but they do not explain the parameters.. That's my problem I think ..

Offline

#4 2007-08-12 11:26 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

Offline

#5 2007-08-12 11:28 AM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

No, I do:

regexec(SomeRegularExpression, MyStringWichShouldBeLookingFor, ParaMeterIDontKnowWhatItIs, ArrayWhereTheMatchedStringsWillBeStored);

Offline

#6 2007-08-12 11:50 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

The snippet of code you posted says different. I just copied it and replaced the long string with "somestring".

You need to compile a regular expression with regcomp and then use the result in further regexec calls. Did you do that at all?

Offline

#7 2007-08-12 12:20 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

aah, no. I didn't..

The problem is, regex isn't well documentated. :(
So, I can't find some good information about the subject, and can't find how regcomp works..

Offline

#8 2007-08-12 12:48 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

It's perfectly documented here, do you have the regex(3)/regcomp/regexec manpage?

Offline

#9 2007-08-12 12:53 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

Yes I do, but I don't understand the regex manpages. Most of the times I got all the information needed out of a man page, but these are wierd. The parameters aren't explained on a way I understand :( :confused:

Offline

#10 2007-08-12 01:42 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

Offline

#11 2007-08-12 04:56 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

no, the integer. Wich I said I didn't understand above. The one I gave 999 as count .

Do you, or someone else, have an example for me what my code should be to ' fix ' it ?

Offline

#12 2007-08-12 06:26 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Segmentation fault(core dumped)

regex_t rgx;
regmatch_t matches[8];

if (regcomp (&rgx, BIG_LONG_REGEX_STRING, REG_EXTENDED))
    die();
if (regexec (&rgx, str_to_match_against, 8, matches, 0)) {
    /* you didn't match... */
} else {
    /* you did match, and now "matches" contains the offsets of matching substrs */
}
regfree (&rgx);

Offline

#13 2007-08-12 07:15 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

I've this:

regex_t rgx;
    regmatch_t matches[8];

    if (regcomp (&rgx, "#<wsse\:BinarySecurityToken Id=\"Compact1\">(.*)</wsse:BinarySecurityToken>(.*)<wst\:BinarySecret>(.*)</wst\:BinarySecret>(.*)<wsse\:BinarySecurityToken Id=\"Compact2\">(.*)</wsse:BinarySecurityToken>(.*)<wsse\:BinarySecurityToken Id=\"Compact3\">(.*)</wsse:BinarySecurityToken>#", REG_EXTENDED))
        die("wattefak?");
    if (regexec (&rgx, dtest, 8, matches, 0)) {
        // error
    }
    regfree (&rgx);

    printf("\r\n--  %s\r\n-- %s\r\n",matches[1],matches[3]);

But still got the same error, ' Segmentation Fault (code dumped) '

Offline

#14 2007-08-12 08:42 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Segmentation fault(core dumped)

Offline

#15 2007-08-13 12:15 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Segmentation fault(core dumped)

Yeah...  I really think you're just not reading the documentation, or even what we're
saying to you here, at all...  All you need to do is read up a bit to see i3839's posting
of exactly what a "regmatch_t" consists of, and it's most definitely NOT a string...
It's a structure containing the beginning and ending offsets within the source string
that you passed to regexec()...

And, like i3839 said: you'd be very well advised to ALWAYS compile with full warnings
enabled, and make sure to always silence all warnings in your code...  That would've
found and solved all of these seg-fault problems for you...

Offline

#16 2007-08-13 07:14 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

* Sorry, lill mistake. Wrong button *

Offline

#17 2007-08-13 07:19 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

hmm

Is there another way of regex-using in C?

'cause I got these errors while compiling..

MSNP15.ns.c:188:24: warning: unknown escape sequence '\:'
MSNP15.ns.c:188:24: warning: unknown escape sequence '\:'
MSNP15.ns.c:188:24: warning: unknown escape sequence '\:'
MSNP15.ns.c:188:24: warning: unknown escape sequence '\:'
MSNP15.ns.c:188:24: warning: unknown escape sequence '\:'

Offline

#18 2007-08-14 01:10 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Segmentation fault(core dumped)

Well, and rightfully so...  "\:" is indeed not a valid C string escape sequence...  What
exactly are you trying to accomplish with it in your regex?  Do you just want a literal
colon?  If so, just use ":"; no need for the backslash in front of it...  Or, do you intend
some different special meaning for "\:"?  It's no standard regex syntax that I recognize,
at least...

Offline

#19 2007-08-14 06:09 PM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

Fixed, But still don't get any output ..

The printf prints:

--  %
-- %

Tho, you see, there is an extra space in the first one. I do have an printf() when the regex shouldn't match, and that's true. It doesn't match. It is an valid regex, Isn't it ?

Offline

#20 2007-08-14 07:31 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Segmentation fault(core dumped)

What printf(), exactly??  The one you posted above, and which is completely and
utterly wrong, as both I and i3839 have explained to you??  If you've replaced it by
some correct version, you haven't posted the code for it yet, so we can't guess what
you might be doing wrong now...

Offline

#21 2007-08-15 07:47 AM

niek
Member
Registered: 2006-12-24
Posts: 109

Re: Segmentation fault(core dumped)

I've replaced all the \: 's by : 's. That's the only change, and, Don't get any errors any more

Offline

#22 2007-08-15 01:39 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Segmentation fault(core dumped)

Offline

  • Index
  • » C
  • » Segmentation fault(core dumped)

Board footer

Powered by FluxBB