Skip to content

Commit

Permalink
avoid NULL dereference on failed malloc
Browse files Browse the repository at this point in the history
* builtin-remote.c (get_one_entry): Use xmalloc, not malloc.

Signed-off-by: Jim Meyering <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
meyering authored and gitster committed Jun 14, 2009
1 parent 4a4b4cd commit ce61595
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ static int get_one_entry(struct remote *remote, void *priv)

if (remote->url_nr > 0) {
utilp = &(string_list_append(remote->name, list)->util);
*utilp = malloc(strlen(remote->url[0])+strlen(" (fetch)")+1);
*utilp = xmalloc(strlen(remote->url[0])+strlen(" (fetch)")+1);
strcpy((char *) *utilp, remote->url[0]);
strcat((char *) *utilp, " (fetch)");
} else
Expand All @@ -1300,7 +1300,7 @@ static int get_one_entry(struct remote *remote, void *priv)
for (i = 0; i < url_nr; i++)
{
utilp = &(string_list_append(remote->name, list)->util);
*utilp = malloc(strlen(url[i])+strlen(" (push)")+1);
*utilp = xmalloc(strlen(url[i])+strlen(" (push)")+1);
strcpy((char *) *utilp, url[i]);
strcat((char *) *utilp, " (push)");
}
Expand Down

0 comments on commit ce61595

Please sign in to comment.