From c1d9d291f2bc55b98d5f25ea7c0ee2f33f16b1b6 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Fri, 24 Dec 2010 13:56:06 +0100 Subject: [PATCH] cmdline (merge-intel): don't limit output len of cmdline_printf() It was using a big buffer in stack. Now use vdprintf() if _GNU_SOURCE is defined, or a malloc + free if not. Signed-off-by: Olivier Matz --- src/lib/cmdline.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index bafaace..6d37885 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -149,14 +149,33 @@ void cmdline_printf(const struct cmdline *cl, const char *fmt, ...) { va_list ap; - char buffer[BUFSIZ]; +#ifdef _GNU_SOURCE + if (cl->s_out < 0) + return; va_start(ap, fmt); - vsnprintf(buffer, 512, fmt, ap); + vdprintf(cl->s_out, fmt, ap); va_end(ap); - if (cl->s_out >= 0) { - write(cl->s_out, buffer, strlen(buffer)); - } +#else + int ret; + char *buf; + + if (cl->s_out < 0) + return; + + buf = malloc(BUFSIZ); + if (buf == NULL) + return; + va_start(ap, fmt); + ret = vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + if (ret < 0) + return; + if (ret >= BUFSIZ) + ret = BUFSIZ - 1; + write(cl->s_out, buf, ret); + free(buf); +#endif } int -- 2.20.1