From 812666c8e66a21e668c0789d0422aa5a7db54961 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Tue, 26 Apr 2005 12:00:58 -0700 Subject: [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 Signed-off-by: Linus Torvalds --- diff-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'diff-tree.c') diff --git a/diff-tree.c b/diff-tree.c index 618fdb616c..3579b5fd11 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