1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-29 20:46:22 -05:00

uemacs: Add xmalloc as a wrapper function for malloc.

xmalloc checks the returned pointer and dies if it failed to allocate
the memory.

Use this new function in window.c.
More places will be converted to use xmalloc latter.

Signed-off-by: Thiago Farina <tfransosi@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Thiago Farina 2010-12-15 23:34:57 -02:00 committed by Linus Torvalds
parent bf3c3ac2bd
commit 6e4aec520e
3 changed files with 12 additions and 4 deletions

View File

@ -11,6 +11,7 @@
#include "edef.h" #include "edef.h"
#include "efunc.h" #include "efunc.h"
#include "line.h" #include "line.h"
#include "wrapper.h"
/* /*
* Reposition dot in the current window to line "n". If the argument is * Reposition dot in the current window to line "n". If the argument is
@ -323,10 +324,7 @@ int splitwind(int f, int n)
mlwrite("Cannot split a %d line window", curwp->w_ntrows); mlwrite("Cannot split a %d line window", curwp->w_ntrows);
return FALSE; return FALSE;
} }
if ((wp = (struct window *)malloc(sizeof(struct window))) == NULL) { wp = xmalloc(sizeof(struct window));
mlwrite("(OUT OF MEMORY)");
return FALSE;
}
++curbp->b_nwnd; /* Displayed twice. */ ++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp; wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp; wp->w_dotp = curwp->w_dotp;

View File

@ -12,3 +12,11 @@ int xmkstemp(char *template)
die("Unable to create temporary file"); die("Unable to create temporary file");
return fd; return fd;
} }
void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret)
die("Out of memory");
return ret;
}

View File

@ -3,4 +3,6 @@
extern int xmkstemp(char *template); extern int xmkstemp(char *template);
extern void *xmalloc(size_t size);
#endif /* WRAPPER_H_ */ #endif /* WRAPPER_H_ */