shithub: riscv

Download patch

ref: 8788c5737b73f1ea7d8fada2ef03e4ed29432af8
parent: 3a47c8bfbe9298fed2b6dcc5ac19a7af4c96c52f
author: Michael Forney <mforney@mforney.org>
date: Thu Sep 29 00:49:00 EDT 2022

patch: fix line bounds check when searching for hunk

--- a/sys/src/cmd/patch.c
+++ b/sys/src/cmd/patch.c
@@ -517,7 +517,7 @@
 	for(fuzz = 0; scanning && fuzz <= nfuzz; fuzz++){
 		scanning = 0;
 		ln = h->oldln - fuzz;
-		if(ln > f->lastln){
+		if(ln > f->lastln && ln < f->nlines){
 			off = f->lines[ln];
 			if(off + len > f->len)
 				continue;
@@ -528,7 +528,7 @@
 			}
 		}
 		ln = h->oldln + fuzz + 1;
-		if(ln <= f->nlines){
+		if(ln > f->lastln && ln < f->nlines){
 			off = f->lines[ln];
 			if(off + len >= f->len)
 				continue;