PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > regexec from regex.h Segmentation fault
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
regexec from regex.h Segmentation fault

Réponse
 
LinkBack Outils de la discussion
Vieux 04/02/2008, 15h17   #1
al.moorthi@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut regexec from regex.h Segmentation fault

the below program is working in Suse and not working on Cent 5:
can any body have the solution ?

#include <regex.h>
#include <stdlib.h>
#include <stdio.h>

int main(){

char cool[] = "http://www.cnn.com:80/wowsers.html";
regex_t test_reg;
regmatch_t matches[3];
int num_matches;


int success = regcomp(&test_reg, "http://([^/]*)(/{0,1}.*)",
REG_EXTENDED | REG_ICASE);
printf("regcomp success = %d\r\n", success);


success = regexec(&test_reg, cool, num_matches, matches, 0);
printf("regexec success = %d\r\n", success);


printf("overall match start index = %d\r\n", matches[0].rm_so);
printf("overall match end index = %d\r\n",
matches[0].rm_eo);
printf("first match start index = %d\r\n", matches[1].rm_so);
printf("first match end index = %d\r\n", matches[1].rm_eo);
printf("second match start index = %d\r\n", matches[2].rm_so);
printf("second match end index = %d\r\n", matches[2].rm_eo);

}

OUTPUT on SuSE(10.2):
../regex
regcomp success = 0
regexec success = 0
overall match start index = 0
overall match end index = 34
first match start index = 7
first match end index = 21
second match start index = 21
second match end index = 34
OUTPUT on Cent(5):
../regex
regcomp success = 0
Segmentation fault

MORE DETAILS:
regex.h are same on both machine.

ldd ./regex ( on Cent 5 )
linux-gate.so.1 => (0x00a43000)
libc.so.6 => /lib/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x0093c000)
glibc-devel-2.5-12 (rpm -qf /usr/include/regex.h)
ldd ./regex ( on SuSE 10.2 )
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7d8c000)
/lib/ld-linux.so.2 (0xb7ee9000)
glibc-devel-2.5-25 (rpm -qf /usr/include/regex.h)
  Réponse avec citation
Vieux 04/02/2008, 15h24   #2
Malcolm McLean
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regexec from regex.h Segmentation fault


<al.moorthi@gmail.com> wrote in message
> int num_matches;
>
> success = regexec(&test_reg, cool, num_matches, matches, 0);
>

Looks suspicious to me. Surely you should pass &num_matches so that
regexec() can fill in the answer?
I don't know the prototype for regexec(), so this may be wrong.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm



  Réponse avec citation
Vieux 04/02/2008, 16h00   #3
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regexec from regex.h Segmentation fault

al.moorthi@gmail.com writes:

> the below program is working in Suse and not working on Cent 5:
> can any body have the solution ?
>
> #include <regex.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> int main(){
>
> char cool[] = "http://www.cnn.com:80/wowsers.html";
> regex_t test_reg;
> regmatch_t matches[3];
> int num_matches;


int num_matches = 3;

You are expected to say how big the matches array is. This is not
really on-topic here. Further problem should go to
comp.unix.programmer since this is a POSIX interface.

--
Ben.
  Réponse avec citation
Vieux 04/02/2008, 16h03   #4
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regexec from regex.h Segmentation fault

Malcolm McLean wrote:
>
> <al.moorthi@gmail.com> wrote in message
>> int num_matches;


make this "int num_matches = 3;" or (better) "size_t num_matches = 3;"

>>
>> success = regexec(&test_reg, cool, num_matches, matches, 0);
>>

> Looks suspicious to me. Surely you should pass &num_matches so that
> regexec() can fill in the answer?
> I don't know the prototype for regexec(), so this may be wrong.


Malcolm's instincts are right.

num_matches needs to be initialized to indicate how many
matches you can handle (loosely speaking).
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10750 seconds with 12 queries