git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Unused pos[] in apply.c

From
PRPavel Roskin <proski@gnu.org>
Date
Jun 1, 2005, 04:20 UTC
Message-ID
<1117599606.13776.26.camel@dv>
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 <proski@gnu.org>
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
Message 1 of 1 in “Unused pos[] in apply.c”
  1. Unused pos[] in apply.cPavel Roskin, Jun 1, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.