unarchive: fix possible segmentation fault in deb_extract()
[oweals/opkg-lede.git] / libbb / xfuncs.c
index c12b28234a1a58360a9781d2de2965c5db15dbc4..2469b6a81de2ea68ae3ba9938f50c96de7282e41 100644 (file)
 #include <unistd.h>
 #include "libbb.h"
 
-
 extern void *xmalloc(size_t size)
 {
        void *ptr = malloc(size);
        if (ptr == NULL && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("malloc");
        return ptr;
 }
 
@@ -38,7 +37,7 @@ extern void *xrealloc(void *ptr, size_t size)
 {
        ptr = realloc(ptr, size);
        if (ptr == NULL && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("realloc");
        return ptr;
 }
 
@@ -46,33 +45,35 @@ extern void *xcalloc(size_t nmemb, size_t size)
 {
        void *ptr = calloc(nmemb, size);
        if (ptr == NULL && nmemb != 0 && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("calloc");
        return ptr;
 }
 
-extern char * xstrdup (const char *s) {
+extern char *xstrdup(const char *s)
+{
        char *t;
 
        if (s == NULL)
                return NULL;
 
-       t = strdup (s);
+       t = strdup(s);
 
        if (t == NULL)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("strdup");
 
        return t;
 }
 
-extern char * xstrndup (const char *s, int n) {
+extern char *xstrndup(const char *s, int n)
+{
        char *t;
 
        if (s == NULL)
                error_msg_and_die("xstrndup bug");
 
        t = xmalloc(++n);
-       
-       return safe_strncpy(t,s,n);
+
+       return safe_strncpy(t, s, n);
 }
 
 FILE *xfopen(const char *path, const char *mode)