Skip to contentSkip to conversation

Unused pos[] in apply.c

PATCH New Pavel Roskin 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Unused pos[] in apply.c

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.

apply.c +3 -3
@@ -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.. */
Signature · 2 lines
Regards,
Pavel Roskin