Message ID | 1455734459-31902-7-git-send-email-drjones@redhat.com |
---|---|
State | Superseded |
Headers | show |
On Wed, Feb 17, 2016 at 07:40:47PM +0100, Andrew Jones wrote: > va_report_xfail has the pattern > > char buf[] > vsnprintf(buf, ...) > puts(buf) > > Before adding another one, replace it with vprintf. > > Suggested-by: David Gibson <david@gibson.dropbear.id.au> > Signed-off-by: Andrew Jones <drjones@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> > --- > lib/libcflat.h | 1 + > lib/printf.c | 14 +++++++++++++- > lib/report.c | 4 +--- > 3 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/lib/libcflat.h b/lib/libcflat.h > index 9747ccdbc9f1d..f7a5728c6759a 100644 > --- a/lib/libcflat.h > +++ b/lib/libcflat.h > @@ -55,6 +55,7 @@ extern void abort(void); > extern int printf(const char *fmt, ...); > extern int snprintf(char *buf, int size, const char *fmt, ...); > extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); > +extern int vprintf(const char *fmt, va_list va); > extern long atol(const char *ptr); > > void report_prefix_push(const char *prefix); > diff --git a/lib/printf.c b/lib/printf.c > index 5d83605afe829..2aec59aa6d6d4 100644 > --- a/lib/printf.c > +++ b/lib/printf.c > @@ -1,5 +1,7 @@ > #include "libcflat.h" > > +#define BUFSZ 2000 > + > typedef struct pstream { > char *buffer; > int remain; > @@ -235,10 +237,20 @@ int snprintf(char *buf, int size, const char *fmt, ...) > return r; > } > > +int vprintf(const char *fmt, va_list va) > +{ > + char buf[BUFSZ]; > + int r; > + > + r = vsnprintf(buf, sizeof(buf), fmt, va); > + puts(buf); > + return r; > +} > + > int printf(const char *fmt, ...) > { > va_list va; > - char buf[2000]; > + char buf[BUFSZ]; > int r; > > va_start(va, fmt); > diff --git a/lib/report.c b/lib/report.c > index 35e664108a921..c29e835b9c751 100644 > --- a/lib/report.c > +++ b/lib/report.c > @@ -47,15 +47,13 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va) > { > char *pass = xfail ? "XPASS" : "PASS"; > char *fail = xfail ? "XFAIL" : "FAIL"; > - char buf[2000]; > > spin_lock(&lock); > > tests++; > printf("%s: ", cond ? pass : fail); > puts(prefixes); > - vsnprintf(buf, sizeof(buf), msg_fmt, va); > - puts(buf); > + vprintf(msg_fmt, va); > puts("\n"); > if (xfail && cond) > failures++;
On 17.02.2016 19:40, Andrew Jones wrote: > va_report_xfail has the pattern > > char buf[] > vsnprintf(buf, ...) > puts(buf) > > Before adding another one, replace it with vprintf. > > Suggested-by: David Gibson <david@gibson.dropbear.id.au> > Signed-off-by: Andrew Jones <drjones@redhat.com> > --- > lib/libcflat.h | 1 + > lib/printf.c | 14 +++++++++++++- > lib/report.c | 4 +--- > 3 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/lib/libcflat.h b/lib/libcflat.h > index 9747ccdbc9f1d..f7a5728c6759a 100644 > --- a/lib/libcflat.h > +++ b/lib/libcflat.h > @@ -55,6 +55,7 @@ extern void abort(void); > extern int printf(const char *fmt, ...); > extern int snprintf(char *buf, int size, const char *fmt, ...); Completely off-topic to your patch, but these declarations above could maybe be improved with __attribute__((format (printf, x, y))) to get some nice format string checks from the compiler. > extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); > +extern int vprintf(const char *fmt, va_list va); > extern long atol(const char *ptr); Back to the topic: Your patch looks fine to me, so: Reviewed-by: Thomas Huth <thuth@redhat.com> -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Feb 18, 2016 at 07:34:28AM +0100, Thomas Huth wrote: > On 17.02.2016 19:40, Andrew Jones wrote: > > va_report_xfail has the pattern > > > > char buf[] > > vsnprintf(buf, ...) > > puts(buf) > > > > Before adding another one, replace it with vprintf. > > > > Suggested-by: David Gibson <david@gibson.dropbear.id.au> > > Signed-off-by: Andrew Jones <drjones@redhat.com> > > --- > > lib/libcflat.h | 1 + > > lib/printf.c | 14 +++++++++++++- > > lib/report.c | 4 +--- > > 3 files changed, 15 insertions(+), 4 deletions(-) > > > > diff --git a/lib/libcflat.h b/lib/libcflat.h > > index 9747ccdbc9f1d..f7a5728c6759a 100644 > > --- a/lib/libcflat.h > > +++ b/lib/libcflat.h > > @@ -55,6 +55,7 @@ extern void abort(void); > > extern int printf(const char *fmt, ...); > > extern int snprintf(char *buf, int size, const char *fmt, ...); > > Completely off-topic to your patch, but these declarations above could > maybe be improved with __attribute__((format (printf, x, y))) to get > some nice format string checks from the compiler. That is a good idea. (/me learns a new gcc attribute). I'll send a separate patch to add those. > > > extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); > > +extern int vprintf(const char *fmt, va_list va); > > extern long atol(const char *ptr); > > Back to the topic: Your patch looks fine to me, so: > > Reviewed-by: Thomas Huth <thuth@redhat.com> Thanks, drew -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/lib/libcflat.h b/lib/libcflat.h index 9747ccdbc9f1d..f7a5728c6759a 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -55,6 +55,7 @@ extern void abort(void); extern int printf(const char *fmt, ...); extern int snprintf(char *buf, int size, const char *fmt, ...); extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); +extern int vprintf(const char *fmt, va_list va); extern long atol(const char *ptr); void report_prefix_push(const char *prefix); diff --git a/lib/printf.c b/lib/printf.c index 5d83605afe829..2aec59aa6d6d4 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -1,5 +1,7 @@ #include "libcflat.h" +#define BUFSZ 2000 + typedef struct pstream { char *buffer; int remain; @@ -235,10 +237,20 @@ int snprintf(char *buf, int size, const char *fmt, ...) return r; } +int vprintf(const char *fmt, va_list va) +{ + char buf[BUFSZ]; + int r; + + r = vsnprintf(buf, sizeof(buf), fmt, va); + puts(buf); + return r; +} + int printf(const char *fmt, ...) { va_list va; - char buf[2000]; + char buf[BUFSZ]; int r; va_start(va, fmt); diff --git a/lib/report.c b/lib/report.c index 35e664108a921..c29e835b9c751 100644 --- a/lib/report.c +++ b/lib/report.c @@ -47,15 +47,13 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va) { char *pass = xfail ? "XPASS" : "PASS"; char *fail = xfail ? "XFAIL" : "FAIL"; - char buf[2000]; spin_lock(&lock); tests++; printf("%s: ", cond ? pass : fail); puts(prefixes); - vsnprintf(buf, sizeof(buf), msg_fmt, va); - puts(buf); + vprintf(msg_fmt, va); puts("\n"); if (xfail && cond) failures++;
va_report_xfail has the pattern char buf[] vsnprintf(buf, ...) puts(buf) Before adding another one, replace it with vprintf. Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Andrew Jones <drjones@redhat.com> --- lib/libcflat.h | 1 + lib/printf.c | 14 +++++++++++++- lib/report.c | 4 +--- 3 files changed, 15 insertions(+), 4 deletions(-)