aboutsummaryrefslogtreecommitdiff
path: root/kmer_utils.c
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-02-24 12:17:15 -0500
committerCalvin Morrison <mutantturkey@gmail.com>2014-02-24 12:17:15 -0500
commitdd39482f495a660d125ed9b4a352993a47e9d7d9 (patch)
treeb51d1754bf6990a8b53e2a79c027afda60672d68 /kmer_utils.c
parent1c2ce90501d87db6431a7f29a37876d61347aff7 (diff)
add more verbose error messages and add more memory checks
Diffstat (limited to 'kmer_utils.c')
-rw-r--r--kmer_utils.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/kmer_utils.c b/kmer_utils.c
index 060e311..81b1e91 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -99,8 +99,10 @@ char *index_to_kmer(unsigned long long index, long kmer) {
size_t j = 0;
char *num_array = calloc(kmer, sizeof(char));
char *ret = calloc(kmer + 1, sizeof(char));
- if(ret == NULL)
+ if(ret == NULL || num_array == NULL) {
+ fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
+ }
// this is the core of the conversion. modulus 4 for base 4 conversion
@@ -172,7 +174,7 @@ unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer
// malloc our return array
unsigned long long * counts = calloc((width+ 1), sizeof(unsigned long long));
if(counts == NULL) {
- fprintf(stderr, strerror(errno));
+ fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
@@ -234,7 +236,7 @@ unsigned long long * get_kmer_counts_from_filename(const char *fn, const unsigne
FILE *fh = fopen(fn, "r");
if(fh == NULL) {
fprintf(stderr, "Could not open %s - %s\n", fn, strerror(errno));
- return 0;
+ return NULL;
}
return get_kmer_counts_from_file(fh, kmer);