aboutsummaryrefslogtreecommitdiff
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
parent1c2ce90501d87db6431a7f29a37876d61347aff7 (diff)
add more verbose error messages and add more memory checks
-rw-r--r--kmer_counts_per_sequence.c18
-rw-r--r--kmer_utils.c8
2 files changed, 16 insertions, 10 deletions
diff --git a/kmer_counts_per_sequence.c b/kmer_counts_per_sequence.c
index 2b95ed1..bd18f04 100644
--- a/kmer_counts_per_sequence.c
+++ b/kmer_counts_per_sequence.c
@@ -131,8 +131,10 @@ int main(int argc, char **argv) {
if(specific_mers) {
sparse = false;
desired_indicies = malloc((width) * sizeof(size_t));
- if(desired_indicies == NULL)
+ if(desired_indicies == NULL) {
+ fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
+ }
num_desired_indicies = load_specific_mers_from_file(mer_fn, kmer, width, desired_indicies);
if(num_desired_indicies == 0) {
fprintf(stderr, "Error: no mers loaded from file");
@@ -142,8 +144,10 @@ int main(int argc, char **argv) {
unsigned long long *counts = malloc((width+ 1) * sizeof(unsigned long long));
- if(counts == NULL)
+ if(counts == NULL) {
+ fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
+ }
unsigned long long sequence = 0;
while ((read = getdelim(&line, &len, '>', fh)) != -1) {
@@ -197,11 +201,11 @@ int main(int argc, char **argv) {
sequence++;
}
-free(counts);
-free(line);
-free(desired_indicies);
-fclose(fh);
+ free(counts);
+ free(line);
+ free(desired_indicies);
+ fclose(fh);
-return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
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);