From 7eda50a673d15320022375360fd220e8381b69ab Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 16 Nov 2018 18:15:22 +0100 Subject: [PATCH] core: Fix a LF problem in the new debug fucntion. * src/debug.c (_gpgme_debug): Print a LF for an empty FORMAT unless we are in legacy mode. --- src/debug.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/debug.c b/src/debug.c index f0b0da0e..81c2a90c 100644 --- a/src/debug.c +++ b/src/debug.c @@ -254,11 +254,12 @@ _gpgme_debug (int level, int mode, const char *func, const char *tagname, { va_list arg_ptr; int saved_errno; + int need_lf; - saved_errno = errno; if (debug_level < level) return 0; + saved_errno = errno; va_start (arg_ptr, format); LOCK (debug_lock); { @@ -280,6 +281,7 @@ _gpgme_debug (int level, int mode, const char *func, const char *tagname, } #endif + need_lf = 0; switch (mode) { case -1: /* Do nothing. */ @@ -300,13 +302,14 @@ _gpgme_debug (int level, int mode, const char *func, const char *tagname, fprintf (errfp, "%s: leave: ", func); break; default: - fprintf (errfp, "%s: m=%d: %s=%p ", func, mode, tagname, tagvalue); + fprintf (errfp, "%s: ?(mode=%d): %s=%p ", func, mode, tagname, tagvalue); break; } + need_lf = (mode != -1 && (!format || !*format)); vfprintf (errfp, format, arg_ptr); va_end (arg_ptr); - if(format && *format && format[strlen (format) - 1] != '\n') + if (need_lf || (format && *format && format[strlen (format) - 1] != '\n')) putc ('\n', errfp); UNLOCK (debug_lock); fflush (errfp);