Use xmalloc() and friends to catch allocation failures
Some places use the standard malloc/strdup without checking if the allocation was successful; they should use xmalloc/xstrdup that check the memory allocation result. Signed-off-by: Dotan Barak <dotanba@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4886b89f8f
commit
e8eec71d6e
4
remote.c
4
remote.c
@ -69,7 +69,7 @@ static const char *alias_url(const char *url)
|
||||
if (!longest)
|
||||
return url;
|
||||
|
||||
ret = malloc(rewrite[longest_i]->baselen +
|
||||
ret = xmalloc(rewrite[longest_i]->baselen +
|
||||
(strlen(url) - longest->len) + 1);
|
||||
strcpy(ret, rewrite[longest_i]->base);
|
||||
strcpy(ret + rewrite[longest_i]->baselen, url + longest->len);
|
||||
@ -152,7 +152,7 @@ static struct branch *make_branch(const char *name, int len)
|
||||
ret->name = xstrndup(name, len);
|
||||
else
|
||||
ret->name = xstrdup(name);
|
||||
refname = malloc(strlen(name) + strlen("refs/heads/") + 1);
|
||||
refname = xmalloc(strlen(name) + strlen("refs/heads/") + 1);
|
||||
strcpy(refname, "refs/heads/");
|
||||
strcpy(refname + strlen("refs/heads/"), ret->name);
|
||||
ret->refname = refname;
|
||||
|
Reference in New Issue
Block a user