From: John Marshall Date: Wed, 24 Jul 2013 13:08:25 +0000 (+0100) Subject: Only canonicalise if there is room, and add docs X-Git-Tag: spawn-final~20^2~1 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=99ca35977ce22dfd14e63927ce974251b54f5cfb;p=klib.git Only canonicalise if there is room, and add docs We could increment SIZE to ensure there would be room, but that would disadvantage people using kstrings for binary data in power-of-2-sized blocks. Instead document that SIZE=KS.l+1 will ensure NUL-termination. This fixes a bug in the previous version when the lm < size) { @@ -89,7 +92,7 @@ static inline int ks_resize(kstring_t *s, size_t size) else return -1; } - s->s[s->l] = '\0'; + if (s->l < s->m) s->s[s->l] = '\0'; return 0; }