From: NeilBrown Date: Sat, 29 Aug 2020 04:17:02 +0000 (+1000) Subject: vpatch: fix problems reported by valgrind. X-Git-Tag: v1.3~16 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=340562c3adbc542bc987c7e6ecc0a226ca415b70;p=wiggle.git vpatch: fix problems reported by valgrind. test code isn't much good if you don't run it... I ran 'make vtest' and fixed the problems reported. Signed-off-by: NeilBrown --- diff --git a/Makefile b/Makefile index 227a0f8..2311067 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ QUIET_CLEAN = $(Q:@=@echo ' CLEAN '$@;) $(BIN)/wiggle : $(BOBJ) $(O)/libwiggle.a - $(QUIET_LINK)$(CC) $^ $(LDLIBS) -o $@ + $(QUIET_LINK)$(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ $(O)/libwiggle.a : $(BLIBOBJ) $(QUIET_AR)ar cr $@ $^ diff --git a/dovtest b/dovtest index b38bb46..bcb3c65 100755 --- a/dovtest +++ b/dovtest @@ -41,7 +41,7 @@ do else $VG $WIGGLE -B orig fi if grep 'ERROR SUMMARY: [1-9]' $vallog > /dev/null 2>&1 - then msg="VALGRIND ERRORS"; xit=1 + then msg="VALGRIND ERRORS"; xit=1 ; mv $vallog $vallog-${dir////-} else msg="SUCCESS"; xit=0 fi echo $path $msg diff --git a/vpatch.c b/vpatch.c index 47e6319..601408b 100644 --- a/vpatch.c +++ b/vpatch.c @@ -1619,6 +1619,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, while (spos.p.m >= 0 && spos.state != 0) prev_mline(&spos, fm, fb, fa, ci.merger, smode); while (!same_mpos(spos, tpos) && + spos.p.m >= 0 && ci.merger[spos.p.m].type != End) next_mline(&spos, fm, fb, fa, ci.merger, smode); @@ -1636,7 +1637,8 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, blank(i--, 0, cols, a_void); tpos = spos; for (i = srow; - i < rows && ci.merger[tpos.p.m].type != End; + i < rows && tpos.p.m >= 0 && + ci.merger[tpos.p.m].type != End; i++) { draw_mline(smode, i, start, cols, fm, fb, fa, ci.merger, tpos, diff --git a/wiggle.h b/wiggle.h index 0de65b2..0aa759b 100644 --- a/wiggle.h +++ b/wiggle.h @@ -45,7 +45,7 @@ struct stream { * elmnt at the start of each hunk which starts with '\0' and * records the line offsets of the hunk. These are 20+ bytes long. * "\0\d{5} \d{5} \d{5}{SP funcname}?\n\0" - * The 3 numbers are: chunk number, starting line, number if lines. + * The 3 numbers are: chunk number, starting line, number of lines. * An element with len==0 marks EOF. */ struct elmnt {