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.
This commit is contained in:
Werner Koch 2018-11-16 18:15:22 +01:00
parent cf42386406
commit 7eda50a673
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -254,11 +254,12 @@ _gpgme_debug (int level, int mode, const char *func, const char *tagname,
{ {
va_list arg_ptr; va_list arg_ptr;
int saved_errno; int saved_errno;
int need_lf;
saved_errno = errno;
if (debug_level < level) if (debug_level < level)
return 0; return 0;
saved_errno = errno;
va_start (arg_ptr, format); va_start (arg_ptr, format);
LOCK (debug_lock); LOCK (debug_lock);
{ {
@ -280,6 +281,7 @@ _gpgme_debug (int level, int mode, const char *func, const char *tagname,
} }
#endif #endif
need_lf = 0;
switch (mode) switch (mode)
{ {
case -1: /* Do nothing. */ 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); fprintf (errfp, "%s: leave: ", func);
break; break;
default: default:
fprintf (errfp, "%s: m=%d: %s=%p ", func, mode, tagname, tagvalue); fprintf (errfp, "%s: ?(mode=%d): %s=%p ", func, mode, tagname, tagvalue);
break; break;
} }
need_lf = (mode != -1 && (!format || !*format));
vfprintf (errfp, format, arg_ptr); vfprintf (errfp, format, arg_ptr);
va_end (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); putc ('\n', errfp);
UNLOCK (debug_lock); UNLOCK (debug_lock);
fflush (errfp); fflush (errfp);