私はC
に比較的新しいだと私は次のように問題がある:私はこれを実行するとRegexc - セグメンテーションフォールト
regex_t re;
regmatch_t matches[2];
int start;
int end;
int count = 0;
int reti = regcomp(&re, "^(?:[a-zA-Z]|[a-zA-Z](?:[a-zA-Z0-9\\-])*[a-zA-Z0-9])(?:\\.(?:[a-zA-Z]|[a-zA-Z](?:[a-zA-Z0-9\\-])*[a-zA-Z0-9]))*$", REG_EXTENDED);
while (1) {
printf("Local = %s\n", local);
reti = regexec(&re, local, 2, matches, 0);
// More code here
}
、私はsegmentation fault
を取得します。
local
は、char *local
と定義され、正しく出力されています。
私はGDB
を使用してコードを実行し、それが問題はラインで発生さ判明:
reti = regexec(&re, local, 2, matches, 0);
私は理由を把握するように見えることはできません。
これはgdb
から出力されます:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7af8d42 in regexec() from /lib/x86_64-linux-gnu/libc.so.6
(gdb) backtrace
#0 0x00007ffff7af8d42 in regexec() from /lib/x86_64-linux-gnu/libc.so.6
#1 0x000000000040092d in email_in (str=0x400aa8 "[email protected]") attestdriver.c:70
#2 0x0000000000400780 in main() at testdriver.c:15
、誰もが問題になるかもしれないものについてどのような考えを持っていますか?
ありがとうございました。
'regcomp()'と 'regexec()'の定義を表示できますか? –
@sunqingyao https://github.com/lattera/glibc/blob/master/posix/regcomp.c#L465-L519 – Siguza
'retcom'の戻り値をチェックして、' regcomp'が実際にコンパイルに成功したことを確認しましたか? – Dolda2000