DORMANTno replies

[PATCH] Unused pos[] in apply.c

From: Pavel Roskin <hidden>
Date: 2016-06-15 22:41:59
Subsystem: the rest · Maintainer: Linus Torvalds

Hello!

gcc 4.0 complains about current cogito (and current git from Linus):

apply.c: In function 'apply_patch':
apply.c:622: warning: 'pos[0]' is used uninitialized in this function
apply.c:624: warning: 'pos[1]' is used uninitialized in this function

Indeed, pos[] is never initialized and never used again.

My understanding of the code is that it's trying to figure out whether
the patch is adding or removing a file.  If the first line for the chunk
or the line count for the old file is not 0, the old file existed, so
the patch is not adding the file.  Conversely, non-zero position or line
count for the new file means we are not deleting it.

Following patch makes the code do what it was meant to do.

Signed-off-by: Pavel Roskin <redacted>
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -611,7 +611,7 @@ static int parse_fragment(char *line, un
 {
 	int added, deleted;
 	int len = linelen(line, size), offset;
-	unsigned long pos[4], oldlines, newlines;
+	unsigned long oldlines, newlines;
 
 	offset = parse_fragment_header(line, len, fragment);
 	if (offset < 0)
@@ -619,9 +619,9 @@ static int parse_fragment(char *line, un
 	oldlines = fragment->oldlines;
 	newlines = fragment->newlines;
 
-	if (patch->is_new < 0 && (pos[0] || oldlines))
+	if (patch->is_new < 0 && (fragment->oldpos || oldlines))
 		patch->is_new = 0;
-	if (patch->is_delete < 0 && (pos[1] || newlines))
+	if (patch->is_delete < 0 && (fragment->newpos || newlines))
 		patch->is_delete = 0;
 
 	/* Parse the thing.. */

-- 
Regards,
Pavel Roskin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help