r706: don't segfault upon wrong FASTA/Q (#111)
The lack of robustness cost me several hours to identify.
This commit is contained in:
parent
3b17d62ccd
commit
b328795051
14
bseq.c
14
bseq.c
|
|
@ -54,15 +54,23 @@ void mm_bseq_close(mm_bseq_file_t *fp)
|
|||
free(fp);
|
||||
}
|
||||
|
||||
static inline char *kstrdup(const kstring_t *s)
|
||||
{
|
||||
char *t;
|
||||
t = (char*)malloc(s->l + 1);
|
||||
memcpy(t, s->s, s->l + 1);
|
||||
return t;
|
||||
}
|
||||
|
||||
static inline void kseq2bseq(kseq_t *ks, mm_bseq1_t *s, int with_qual)
|
||||
{
|
||||
int i;
|
||||
s->name = strdup(ks->name.s);
|
||||
s->seq = strdup(ks->seq.s);
|
||||
s->name = kstrdup(&ks->name);
|
||||
s->seq = kstrdup(&ks->seq);
|
||||
for (i = 0; i < ks->seq.l; ++i) // convert U to T
|
||||
if (s->seq[i] == 'u' || s->seq[i] == 'U')
|
||||
--s->seq[i];
|
||||
s->qual = with_qual && ks->qual.l? strdup(ks->qual.s) : 0;
|
||||
s->qual = with_qual && ks->qual.l? kstrdup(&ks->qual) : 0;
|
||||
s->l_seq = ks->seq.l;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue