r706: don't segfault upon wrong FASTA/Q (#111)

The lack of robustness cost me several hours to identify.
This commit is contained in:
Heng Li 2018-02-13 10:00:22 -05:00
parent 3b17d62ccd
commit b328795051
2 changed files with 12 additions and 4 deletions

14
bseq.c
View File

@ -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;
}

2
main.c
View File

@ -6,7 +6,7 @@
#include "mmpriv.h"
#include "getopt.h"
#define MM_VERSION "2.8-r703-dirty"
#define MM_VERSION "2.8-r706-dirty"
#ifdef __linux__
#include <sys/resource.h>