shithub: riscv

Download patch

ref: 8f1867a19f7ca881a32878dcee08ddce11b5db36
parent: 3ebeabebde7cb1758666cab32a73658f516bb199
author: Michael Forney <mforney@mforney.org>
date: Mon Oct 3 01:51:24 EDT 2022

patch: fix uninitialized Fbuf during dry run

--- a/sys/src/cmd/patch.c
+++ b/sys/src/cmd/patch.c
@@ -568,10 +568,11 @@
 	for(i = 0; i < p->nhunk; i++){
 		h = &p->hunk[i];
 		if(curfile == nil || strcmp(curfile, h->newpath) != 0){
-			if(!dryrun)
+			if(!dryrun){
 				slurp(&f, h->oldpath);
+				e = f.buf;
+			}
 			curfile = h->newpath;
-			e = f.buf;
 		}
 		if(!dryrun){
 			s = e;
@@ -581,7 +582,8 @@
 			e += h->oldlen;
 		}
 		if(i+1 == p->nhunk || strcmp(curfile, p->hunk[i+1].newpath) != 0){
-			o = append(o, &osz, e, f.buf + f.len);
+			if(!dryrun)
+				o = append(o, &osz, e, f.buf + f.len);
 			blat(h->oldpath, h->newpath, o, osz);
 			osz = 0;
 		}