]> git.neil.brown.name Git - wiggle.git/commitdiff
Avoid use of undefined variable in bestmatch.
authorNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 08:08:08 +0000 (18:08 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 08:08:08 +0000 (18:08 +1000)
When v->val is <= 0, v->k doesn't mean anything and isn't needed, so
avoid using it.  This helps make valgrind happy.

Signed-off-by: NeilBrown <neilb@suse.de>
bestmatch.c

index 89e8c2d14ad4ab35ae18c0f89f116b9960340359..4750425cf486b4b36c13424c8c8c19e3d26d0c4b 100644 (file)
@@ -59,7 +59,7 @@
 struct v {
        int x,y;  /* location of start of match */
        int val;  /* value of match from x,y to here */
-       int k;    /* diagonal of last match */
+       int k;    /* diagonal of last match - if val > 0 */
        int inmatch; /* 1 if last point was a match */
        int c; /* chunk number */
 };
@@ -112,7 +112,7 @@ static inline void update_value(struct v *v, int dir, int k, int x)
                v->val += 2+v->inmatch;
                v->inmatch = 1;
                v->k = k;
-       } else {
+       } else if (v->val > 0) {
                v->inmatch = 0;
                if (dir * (v->k - k) > 0) {
                        /* other half of replacement */
@@ -121,6 +121,7 @@ static inline void update_value(struct v *v, int dir, int k, int x)
                }
        }
 }
+
 static inline int best_val(struct v *v, int max)
 {
        if (v->val <= 0)