summaryrefslogtreecommitdiff
path: root/diff-tree.c
diff options
context:
space:
mode:
authorChristopher Li <git@chrisli.org>2005-04-26 19:00:58 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-26 19:00:58 (GMT)
commit812666c8e66a21e668c0789d0422aa5a7db54961 (patch)
treeb98a096f4b3c70aac3110f905a1367c23b402cca /diff-tree.c
parentf2a19340ada1188e278d5b198d3466ed7411e2d4 (diff)
downloadgit-812666c8e66a21e668c0789d0422aa5a7db54961.zip
git-812666c8e66a21e668c0789d0422aa5a7db54961.tar.gz
git-812666c8e66a21e668c0789d0422aa5a7db54961.tar.bz2
[PATCH] introduce xmalloc and xrealloc
Introduce xmalloc and xrealloc to die gracefully with a descriptive message when out of memory, rather than taking a SIGSEGV. Signed-off-by: Christopher Li<chrislgit@chrisli.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diff-tree.c')
-rw-r--r--diff-tree.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/diff-tree.c b/diff-tree.c
index 618fdb6..3579b5f 100644
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -37,7 +37,7 @@ static const unsigned char *extract(void *tree, unsigned long size, const char *
static char *malloc_base(const char *base, const char *path, int pathlen)
{
int baselen = strlen(base);
- char *newbase = malloc(baselen + pathlen + 2);
+ char *newbase = xmalloc(baselen + pathlen + 2);
memcpy(newbase, base, baselen);
memcpy(newbase + baselen, path, pathlen);
memcpy(newbase + baselen + pathlen, "/", 2);
@@ -270,7 +270,7 @@ int main(int argc, char **argv)
paths = &argv[3];
nr_paths = argc - 3;
- pathlens = malloc(nr_paths * sizeof(int));
+ pathlens = xmalloc(nr_paths * sizeof(int));
for (i=0; i<nr_paths; i++)
pathlens[i] = strlen(paths[i]);
}