]> git.kaiwu.me - klib.git/commitdiff
another bug in u8; allow **qry set to NULL
authorHeng Li <lh3@me.com>
Fri, 2 Mar 2012 23:52:38 +0000 (18:52 -0500)
committerHeng Li <lh3@me.com>
Fri, 2 Mar 2012 23:52:38 +0000 (18:52 -0500)
ksw.c
ksw.h

diff --git a/ksw.c b/ksw.c
index 3f0fea8b94432338e7dcc65aa2ca53584b7ce611..15301c00216ac44d0e2ab47103e92e072676c22f 100644 (file)
--- a/ksw.c
+++ b/ksw.c
@@ -194,7 +194,7 @@ end_loop16:
                        gmax = imax; te = i; // te is the end position on the target
                        for (j = 0; LIKELY(j < slen); ++j) // keep the H1 vector
                                _mm_store_si128(Hmax + j, _mm_load_si128(H1 + j));
-                       if (gmax + q->shift >= 255 || gmax + q->shift >= endsc) break;
+                       if (gmax + q->shift >= 255 || gmax >= endsc) break;
                }
                S = H1; H1 = H0; H0 = S; // swap H0 and H1
        }
@@ -333,10 +333,12 @@ kswr_t ksw_align(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, con
        kswr_t r, rr;
        kswr_t (*func)(kswq_t*, int, const uint8_t*, int, int, int);
 
-       if (*qry) q = *qry;
-       else *qry = q = ksw_qinit((xtra&KSW_XBYTE)? 1 : 2, qlen, query, m, mat);
+       if (qry == 0 || *qry == 0)
+               q = ksw_qinit((xtra&KSW_XBYTE)? 1 : 2, qlen, query, m, mat);
+       if (qry && *qry == 0) *qry = q;
        func = q->size == 2? ksw_i16 : ksw_u8;
        r = func(q, tlen, target, gapo, gape, xtra);
+       if (qry == 0) free(q);
        if ((xtra&KSW_XSTART) == 0 || ((xtra&KSW_XSUBO) && r.score < (xtra&0xffff))) return r;
        revseq(r.qe + 1, query); revseq(r.te + 1, target); // +1 because qe/te points to the exact end, not the position after the end
        q = ksw_qinit((*qry)->size, r.qe + 1, query, m, mat);
diff --git a/ksw.h b/ksw.h
index 66927b7108ae7520ae1c241185e4f12036ec1502..e1ecf8d4963c48c4a09e9b324c4d4ad799817b87 100644 (file)
--- a/ksw.h
+++ b/ksw.h
@@ -57,7 +57,8 @@ extern "C" {
         * and when the function returns, *qry will point to the profile, which can
         * be deallocated simply by free(). If one query is aligned against multiple
         * target sequences, *qry should be set to NULL during the first call and
-        * freed after the last call.
+        * freed after the last call. Note that qry can equal 0. In this case, the
+        * query profile will be deallocated in ksw_align().
         */
        kswr_t ksw_align(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, const int8_t *mat, int gapo, int gape, int xtra, kswq_t **qry);