X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fxalloc.h;h=ac24ebc6b424a0b0f504de5a40525c36f217e4f2;hb=953f5b4231bbbb8269bb0c55b96a1c8c4bb34a59;hp=34dac3ccfe260b988fb33abce72b71f3f2508eff;hpb=5822f817aa802c2c5a83e9d99a8ae78cb822799b;p=tinc diff --git a/src/xalloc.h b/src/xalloc.h index 34dac3cc..ac24ebc6 100644 --- a/src/xalloc.h +++ b/src/xalloc.h @@ -21,53 +21,71 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -static inline void *xmalloc(size_t n) __attribute__ ((__malloc__)); +static inline void *xmalloc(size_t n) __attribute__((__malloc__)); static inline void *xmalloc(size_t n) { void *p = malloc(n); - if(!p) + + if(!p) { abort(); + } + return p; } -static inline void *xzalloc(size_t n) __attribute__ ((__malloc__)); +static inline void *xzalloc(size_t n) __attribute__((__malloc__)); static inline void *xzalloc(size_t n) { void *p = calloc(1, n); - if(!p) + + if(!p) { abort(); + } + return p; } static inline void *xrealloc(void *p, size_t n) { p = realloc(p, n); - if(!p) + + if(!p) { abort(); + } + return p; } -static inline char *xstrdup(const char *s) __attribute__ ((__malloc__)); +static inline char *xstrdup(const char *s) __attribute__((__malloc__, __nonnull__)); static inline char *xstrdup(const char *s) { char *p = strdup(s); - if(!p) + + if(!p) { abort(); + } + return p; } static inline int xvasprintf(char **strp, const char *fmt, va_list ap) { #ifdef HAVE_MINGW char buf[1024]; - int result = vsnprintf(buf, sizeof buf, fmt, ap); - if(result < 0) + int result = vsnprintf(buf, sizeof(buf), fmt, ap); + + if(result < 0) { abort(); + } + *strp = xstrdup(buf); #else int result = vasprintf(strp, fmt, ap); - if(result < 0) + + if(result < 0) { abort(); + } + #endif return result; } -static inline int xasprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__(printf, 2, 3))); +static inline int xasprintf(char **strp, const char *fmt, ...) __attribute__((__format__(printf, 2, 3))); static inline int xasprintf(char **strp, const char *fmt, ...) { va_list ap; va_start(ap, fmt);