Skip to content

Commit

Permalink
commit.c: Remove backward goto in read_craft_line()
Browse files Browse the repository at this point in the history
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.  It in general is a
better style to have an exception handling out of line from the main
codepath and make error codepath jump forward.

Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ralf Thielow authored and gitster committed Dec 1, 2010
1 parent 208247a commit df5d43b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions commit.c
Expand Up @@ -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;
Expand All @@ -155,6 +151,11 @@ 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)
Expand Down

0 comments on commit df5d43b

Please sign in to comment.