diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-01-17 16:13:49 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-01-17 16:13:49 -0500 |
commit | 97febe91b23883f058df0c9bf99730ced8ce94ea (patch) | |
tree | b3114a7fdbccf9bd8a2089c4a08d56b63cb4350d | |
parent | 468f3d2c268ebee5bade389aebe368d2134e937b (diff) |
add in pointer fix
-rw-r--r-- | kmer_utils.c | 17 |
1 files 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); |