[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>
This commit is contained in:
Christopher Li
2005-04-26 12:00:58 -07:00
committed by Linus Torvalds
parent f2a19340ad
commit 812666c8e6
18 changed files with 54 additions and 41 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "strbuf.h"
#include "cache.h"
void strbuf_init(struct strbuf *sb) {
sb->buf = 0;
@ -15,7 +16,7 @@ static void strbuf_begin(struct strbuf *sb) {
static void inline strbuf_add(struct strbuf *sb, int ch) {
if (sb->alloc <= sb->len) {
sb->alloc = sb->alloc * 3 / 2 + 16;
sb->buf = realloc(sb->buf, sb->alloc);
sb->buf = xrealloc(sb->buf, sb->alloc);
}
sb->buf[sb->len++] = ch;
}