X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fxmalloc.c;h=a1b1fe8be87704d3cacdf37de7e2f728f1b9a2f8;hp=a6874332091f1685ba14f863b19ca0d286ecfc77;hb=d49a336658d772821bee2dbe97df3d4f748c8c4c;hpb=5eb72b73d3cd842e71e525413a46a55644ac3583 diff --git a/src/xmalloc.c b/src/xmalloc.c index a6874332..a1b1fe8b 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -113,9 +113,12 @@ char *xstrdup(const char *s) { char *p; + if(!s) + return NULL; + p = strdup(s); if(!p) - xalloc_fail (s ? (int)strlen(s) : 0); + xalloc_fail ((int)strlen(s)); return p; } @@ -152,6 +155,7 @@ int xvasprintf(char **strp, const char *fmt, va_list ap) { int result = vsnprintf(buf, sizeof buf, fmt, ap); if(result < 0) exit(xalloc_exit_failure); + buf[sizeof buf - 1] = 0; *strp = xstrdup(buf); #else int result = vasprintf(strp, fmt, ap);