slstatus

My fork of https://tools.suckless.org/slstatus/
git clone https://git.inz.fi/slstatus
Log | Files | Refs | README | LICENSE

commit 046e273a7eb270f4b275c02546e4547d8cfc2a82
parent 83e84bebb6accdf0971bfa09a519d8cee37b0237
Author: Daniel Walter <d.walter@0x90.at>
Date:   Thu, 10 Mar 2016 11:49:48 +0100

simplify smprintf by using vasprintf

Diffstat:
Mconfig.mk | 2+-
Mslstatus.c | 17+++--------------
2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/config.mk b/config.mk @@ -15,7 +15,7 @@ INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = -g ${LIBS} diff --git 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;