X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/175844da0f561395d8429e9b8f8e9ad3d561fa50..410ba38a0160da8cbcc81dddd704ae9c7f6d15e2:/slstatus.c?ds=sidebyside diff --git a/slstatus.c b/slstatus.c index 42e5751..214f667 100644 --- a/slstatus.c +++ b/slstatus.c @@ -40,21 +40,10 @@ char * smprintf(char *fmt, ...) { va_list fmtargs; - char *ret; - int len; - - va_start(fmtargs, fmt); - len = vsnprintf(NULL, 0, fmt, fmtargs); - va_end(fmtargs); - - ret = malloc(++len); - if (ret == NULL) { - fprintf(stderr, "Malloc error."); - exit(1); - } - + char *ret = NULL; va_start(fmtargs, fmt); - vsnprintf(ret, len, fmt, fmtargs); + if (vasprintf(&ret, fmt, fmtargs) < 0) + return NULL; va_end(fmtargs); return ret;