]> git.donarmstrong.com Git - rsem.git/blobdiff - LenDist.h
Fixed a bug in perl scripts for printing error messages
[rsem.git] / LenDist.h
index d7b2ba33631dcca513f5acfe1ca6cde41f6daefc..90d47d74522cbc90088ff8267b387046a533a0e3 100644 (file)
--- a/LenDist.h
+++ b/LenDist.h
@@ -3,6 +3,7 @@
 
 #include<cstdio>
 #include<cstring>
+#include<cstdlib>
 #include<cassert>
 #include<algorithm>
 
@@ -189,6 +190,8 @@ void LenDist::finish() {
                sum += pdf[i];
        }
 
+       if (sum <= EPSILON) { fprintf(stderr, "No valid read to estimate the length distribution!\n"); exit(-1); }
+
        for (int i = 1; i <= span; i++) {
                pdf[i] = pdf[i] / sum;
                cdf[i] = cdf[i - 1] + pdf[i];
@@ -217,12 +220,12 @@ void LenDist::read(FILE *fi) {
        delete[] pdf;
        delete[] cdf;
 
-       fscanf(fi, "%d %d %d", &lb, &ub, &span);
+       assert(fscanf(fi, "%d %d %d", &lb, &ub, &span) == 3);
        pdf = new double[span + 1];
        cdf = new double[span + 1];
        pdf[0] = cdf[0] = 0.0;
        for (int i = 1; i <= span; i++) {
-               fscanf(fi, "%lf", &pdf[i]);
+               assert(fscanf(fi, "%lf", &pdf[i]) == 1);
                cdf[i] = cdf[i - 1] + pdf[i];
        }