From 510a8001307afc24199d22bbfb7730c972ca6d69 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 11 Nov 2013 19:42:48 -0500 Subject: fix warnings --- kmer_total_count.c | 35 +++++++++++++++++++++-------------- kmer_utils.h | 1 + 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/kmer_total_count.c b/kmer_total_count.c index 8310e00..57d4fcc 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { char *filename = NULL; - unsigned int kmer = NULL; + unsigned int kmer = 0; bool nonzero = 0; bool label = 0; @@ -21,9 +21,7 @@ int main(int argc, char **argv) { unsigned long long width = 0; - unsigned long long i = 0; - - long long j = 0; + unsigned long long i = 0; static struct option long_options[] = { {"input", required_argument, 0, 'i'}, @@ -69,7 +67,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: filename (-i) must be supplied\n"); exit(EXIT_FAILURE); } - if(kmer == NULL && !kmer_set) { + if(kmer == 0 && !kmer_set) { fprintf(stderr, "Error: kmer (-k) must be supplied\n"); exit(EXIT_FAILURE); } @@ -87,26 +85,35 @@ int main(int argc, char **argv) { // if labels is set, print out our labels if(label) { for(i = 0; i < width; i++) - if(counts[i] != 0) - fprintf(stdout, "%s\t%llu\n", index_to_kmer(i, kmer), counts[i]); - + if(counts[i] != 0) { + char *kmer_str = index_to_kmer(i, kmer); + fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]); + free(kmer_str); + } + } else { for(i = 0; i < width; i++) if(counts[i] != 0) fprintf(stdout, "%llu\t%llu\n", i, counts[i]); - + } } // If we aren't printing nonzeros print everything else { if(label) { - for(i = 0; i < width; i++) - fprintf(stdout, "%s\t%llu\n", index_to_kmer(i, kmer), counts[i]); - } + for(i = 0; i < width; i++) { + if(counts[i] != 0) { + char *kmer_str = index_to_kmer(i, kmer); + fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]); + free(kmer_str); + } + } + } else { - for(i = 0; i < width; i=i+4) - fprintf(stdout, "%llu\n%llu\n%llu\n%llu\n", counts[i], counts[i+1], counts[i+2], counts[i+3]); + for(i = 0; i < width; i=i+4) { + fprintf(stdout, "%llu\n%llu\n%llu\n%llu\n", counts[i], counts[i+1], counts[i+2], counts[i+3]); + } } } return EXIT_SUCCESS; diff --git a/kmer_utils.h b/kmer_utils.h index 4ed5928..762c20c 100644 --- a/kmer_utils.h +++ b/kmer_utils.h @@ -1,6 +1,7 @@ // Kmer functions void convert_kmer_to_num(char *str, const unsigned long length); unsigned long num_to_index(const char *str, const int kmer, const long error_pos); +char *index_to_kmer(unsigned long long index, long kmer); unsigned long long * get_kmer_counts_from_file(const char *fn, const int kmer); // Utility functions -- cgit v1.2.3 From 5d12ff8c86fc82b2800063ecd14008a5e34fd946 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 11 Nov 2013 19:42:57 -0500 Subject: fix memleak --- kmer_utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kmer_utils.c b/kmer_utils.c index 2a739d6..5e24584 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -185,5 +185,6 @@ unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned in } } + free(line); return counts; } -- cgit v1.2.3