From 97febe91b23883f058df0c9bf99730ced8ce94ea Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Fri, 17 Jan 2014 16:13:49 -0500 Subject: add in pointer fix --- kmer_utils.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kmer_utils.c b/kmer_utils.c index 6e11a38..a2fed0e 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -11,6 +11,7 @@ #define ERROR 5 #define SPACE 6 +#define BUFSIZ 256 const unsigned char kmer_alpha[256] = // \n @@ -174,14 +175,18 @@ unsigned long long *kmer_counts_from_file(FILE *fh, const unsigned int kmer) { exit(EXIT_FAILURE); } - while((len = fread_save_n_bytes(buffer, fh, kmer, BUFSIZ - 1, len)) != NULL) { + size_t save_size = kmer - 1; + while((len = fread_save_n_bytes(buffer, fh, save_size, BUFSIZ - 1, len)) != NULL) { size_t i; - - char *ptr = buffer; - if(started) - ptr = buffer + kmer; + char *ptr = buffer + save_size; + size_t ptr_len = len; + + if(!started) { + ptr_len = len + save_size; + ptr = buffer; + } - header = translate_nucleotides_to_numbers(ptr, len, kmer_alpha, header); + header = translate_nucleotides_to_numbers(ptr, ptr_len, kmer_alpha, header); for(i = 0; i < (len - kmer + 1); i++) { size_t mer = calculate_mer(buffer, len, &i, kmer, width); -- cgit v1.2.3