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

[PATCH] commit: Remove backward goto in read_craft_line()

From
Ralf Thielow <ralf.thielow@googlemail.com>
Date
Dec 1, 2010, 19:59 UTC
Message-ID
<1291233546-4962-1-git-send-email-ralf.thielow@googlemail.com>
 Bad graft data is noticed in several places in read_graft_line and
 in each case we go back to the first site of detection.  Move the
 error handling to the end of the function for better readability.
Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com>
---
 commit.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/commit.c b/commit.c
index 0094ec1..642ee34 100644
--- a/commit.c
+++ b/commit.c
@@ -137,12 +137,8 @@ struct commit_graft *read_graft_line(char *buf, int len)
 		buf[--len] = '\0';
 	if (buf[0] == '#' || buf[0] == '\0')
 		return NULL;
-	if ((len + 1) % 41) {
-	bad_graft_data:
-		error("bad graft data: %s", buf);
-		free(graft);
-		return NULL;
-	}
+	if ((len + 1) % 41)
+		goto bad_graft_data;
 	i = (len + 1) / 41 - 1;
 	graft = xmalloc(sizeof(*graft) + 20 * i);
 	graft->nr_parent = i;
@@ -155,6 +151,10 @@ struct commit_graft *read_graft_line(char *buf, int len)
 			goto bad_graft_data;
 	}
 	return graft;
+ bad_graft_data:
+	error("bad graft data: %s", buf);
+	free(graft);
+	return NULL;
 }
 
 static int read_graft_file(const char *graft_file)
-- 
1.7.1
Message 1 of 1 in “commit: Remove backward goto in read_craft_line()”
  1. commit: Remove backward goto in read_craft_line()Ralf Thielow, Dec 1, 2010

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.