diff options
author | Neal H. Walfield <[email protected]> | 2015-03-31 12:23:13 +0000 |
---|---|---|
committer | Neal H. Walfield <[email protected]> | 2015-03-31 12:23:13 +0000 |
commit | 802eec0ca49b92104c92f18c9a6a04c34de74168 (patch) | |
tree | d31a4a29c54430f8a5f17898e7f50fa7978f43d3 /dirmngr/ks-engine-ldap.c | |
parent | dirmngr: Correct indentation. (diff) | |
download | gnupg-802eec0ca49b92104c92f18c9a6a04c34de74168.tar.gz gnupg-802eec0ca49b92104c92f18c9a6a04c34de74168.zip |
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 <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | dirmngr/ks-engine-ldap.c | 27 |
1 files 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"); } } |