I encountered a wired segmentation error. I am developing software in C using the Eclipse CDT. When I run my program on the terminal (Ubuntu 10, 64 bit), it simply reports "Segmentation Error". However, when I debug using gdb in Eclipse, it ends and the result is correct.
I understand that there can be many reasons for segmentation errors. And I'm sorry that I can not show my code, since I do not know where the problem may be ...
But can someone help me, is there some kind of situation that can happen in my case: segmentation error on terminals, as well as good debugging? Many thanks.
Thank you all. I spent some time learning valgrind. I just fixed the error by replacing malloc () with realloc (). The call is followed by two memcpy. This is the reason? Here is the snippet code:
bwa_seq_t *merge_seq (bwa_seq_t *s1, bwa_seq_t *s2) {
ubyte_t *seq1, *seq2, *tmp;
if (!s1 || !s2)
return 0;
seq1 = s1->seq;
seq2 = s2->seq;
tmp = (ubyte_t*) calloc (sizeof(ubyte_t), (s2->len + s1->len + 1));
memcpy(tmp, seq1, sizeof(ubyte_t) * s1->len);
memcpy(&tmp[s1->len], seq2, sizeof(ubyte_t) * s2->len);
s1->len += s2->len;
tmp[s1->len] = '\0';
s1->seq = tmp;
return s1;
}
Can someone explain why?
source
share