changeset 1149:2d7f75e31316

Yet another patch bug, this one due to @@ -1 +1,3 @@ (because the FSF made ,1 implicit, obviously the file format wouldn't be simple or consistent with them involved...)
author Rob Landley <rob@landley.net>
date Wed, 30 Jun 2010 16:01:15 -0500
parents 66c29043b5ca
children 5ce47f84a1d1
files sources/patches/toybox-patch2.patch
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/patches/toybox-patch2.patch	Wed Jun 30 16:01:15 2010 -0500
@@ -0,0 +1,50 @@
+The @@ -1,2 +3,4 @@ lines treat ,1 as implied, so the format isn't regular.
+(Yes, this was designed by the FSF, what gave it away?)
+
+diff -r 35c8beb54800 toys/patch.c
+--- a/toys/patch.c	Sun Feb 28 14:11:41 2010 -0600
++++ b/toys/patch.c	Wed Jun 30 14:26:46 2010 -0500
+@@ -51,7 +51,8 @@
+ 	long prefix;
+ 
+ 	struct double_list *current_hunk;
+-	long oldline, oldlen, newline, newlen, linenum;
++	long oldline, oldlen, newline, newlen;
++	long linenum;
+ 	int context, state, filein, fileout, filepatch, hunknum;
+ 	char *tempname;
+ )
+@@ -308,14 +309,19 @@
+ 			// way the patch man page says, so you have to read the first hunk
+ 			// and _guess_.
+ 
+-		// Start a new hunk?
++		// Start a new hunk?  Usually @@ -oldline,oldlen +newline,newlen @@
++		// but a missing ,value means the value is 1.
+ 		} else if (state == 1 && !strncmp("@@ -", patchline, 4)) {
+ 			int i;
++			char *s = patchline+4;
+ 
+-			i = sscanf(patchline+4, "%ld,%ld +%ld,%ld", &TT.oldline,
+-						&TT.oldlen, &TT.newline, &TT.newlen);
+-			if (i != 4)
+-				error_exit("Corrupt hunk %d at %ld\n", TT.hunknum, TT.linenum);
++			// Read oldline[,oldlen] +newline[,newlen]
++
++			TT.oldlen = TT.newlen = 1;
++			TT.oldline = strtol(s, &s, 10);
++			if (*s == ',') TT.oldlen=strtol(s+1, &s, 10);
++			TT.newline = strtol(s+2, &s, 10);
++			if (*s == ',') TT.newlen = strtol(s+1, &s, 10);
+ 
+ 			TT.context = 0;
+ 			state = 2;
+@@ -323,7 +329,7 @@
+ 			// If this is the first hunk, open the file.
+ 			if (TT.filein == -1) {
+ 				int oldsum, newsum, del = 0;
+-				char *s, *name;
++				char *name;
+ 
+  				oldsum = TT.oldline + TT.oldlen;
+ 				newsum = TT.newline + TT.newlen;