From 802eec0ca49b92104c92f18c9a6a04c34de74168 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 31 Mar 2015 14:23:13 +0200 Subject: [PATCH] dirmngr: Simplify truncation of long strings in debug code. * dirmngr/ks-engine-ldap.c (modlist_dump): Simplify truncation of long strings. -- Signed-off-by: Neal H. Walfield --- dirmngr/ks-engine-ldap.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/dirmngr/ks-engine-ldap.c b/dirmngr/ks-engine-ldap.c index 236f923ae..66e496409 100644 --- a/dirmngr/ks-engine-ldap.c +++ b/dirmngr/ks-engine-ldap.c @@ -1440,29 +1440,22 @@ modlist_dump (LDAPMod **modlist, estream_t output) for ((ptr = (*m)->mod_values), (i = 1); ptr && *ptr; ptr++, i ++) { - /* At most about 10 lines. */ + /* Assuming terminals are about 80 characters wide, + display at most most about 10 lines of debugging + output. If we do trim the buffer, append '...' to + the end. */ const int max_len = 10 * 70; size_t value_len = strlen (*ptr); - char buffer[max_len + 4]; - char *temp; - int elided = 0; - if (value_len > max_len) - { - temp = buffer; - memcpy (temp, *ptr, max_len); - temp[max_len] = temp[max_len + 1] = temp[max_len + 2] = '.'; - temp[max_len + 3] = 0; - elided = 1; - } - else - temp = *ptr; + int elide = value_len > max_len; if (multi) es_fprintf (output, " %d. ", i); - es_fprintf (output, "`%s'", temp); - if (elided) - es_fprintf (output, " (%zd bytes elided)", + es_fprintf (output, "`%.*s", max_len, *ptr); + if (elide) + es_fprintf (output, "...' (%zd bytes elided)", value_len - max_len); + else + es_fprintf (output, "'"); es_fprintf (output, "\n"); } }