(wrong string) ée

From: <git_AT_suckless.org>
Date: Mon, 2 May 2016 13:56:06 +0200 (CEST)

commit e82b5e111223c34deb1e200c9f7cc2ecff9efb01
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Mon May 2 01:02:41 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Mon May 2 01:02:41 2016 +0200

    zstr: do not calculate the exact output size, calculate something easier
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/src/zstr.c b/src/zstr.c
index 6a577b9..81d2060 100644
--- a/src/zstr.c
+++ b/src/zstr.c
_AT_@ -70,15 +70,11 @@ zstr(z_t a, char *b, size_t n)
         }
 
         if (!n) {
- /* This is not the most efficient way to handle this. It should
- * be faster to allocate buffers that sprintint_fix and
- * sprintint_min print to, and then allocate `b` and copy the
- * buffers in reverse order into `b`. However, that is an overly
- * complicated solution. You probably already know the maximum
- * length or do not care about performance. Another disadvantage
- * with calculating the length before-hand, means that it is not
- * possible to reallocate `b` if it is too small. */
- n = zstr_length(a, 10);
+ /* Calculate a value that is at least the number of
+ * digits required to store the string. The overshoot
+ * is not too signicant. */
+ n = (20 * BITS_PER_CHAR / 64 + (BITS_PER_CHAR == 8)) * a->used;
+ /* Note, depends on a ≠ as ensure above. */
         }
 
         if (unlikely(!b) && unlikely(!(b = libzahl_temp_allocation = malloc(n + 1))))
Received on Mon May 02 2016 - 13:56:06 CEST

This archive was generated by hypermail 2.3.0 : Mon May 02 2016 - 14:00:24 CEST