From be6667e95f04bd65475d71c16d2789792c1e787e Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Tue, 29 Oct 2013 13:25:27 -0400 Subject: Fix a nasty bug in kmer-counting code Memset of course does not deal properly with the unsigned long long type so we need to compensate by doing sizeof(unsigned long long) * width to fix the issue --- src/c/quikr_train.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/c/quikr_train.c b/src/c/quikr_train.c index 4d66b9d..0c4c136 100644 --- a/src/c/quikr_train.c +++ b/src/c/quikr_train.c @@ -160,7 +160,7 @@ int main(int argc, char **argv) { gzprintf(output, "%d\n", kmer); // malloc our return array - unsigned long long * counts = malloc((width+ 1) * sizeof(unsigned long long)); + unsigned long long * counts = malloc((width + 1) * sizeof(unsigned long long)); if(counts == NULL) { fprintf(stderr, strerror(errno)); exit(EXIT_FAILURE); @@ -216,7 +216,8 @@ int main(int argc, char **argv) { } // set counts to zero - memset(counts, 0, width); + memset(counts, 0, width * sizeof(counts)); + // loop through our string to process each k-mer for(position = 0; position < (seq_length - kmer + 1); position++) { unsigned long mer = 0; -- cgit v1.2.3