Fix bug in strbuf_puts(), not always appending nul

This commit is contained in:
Andrew Bettison 2013-02-20 14:28:06 +10:30
parent 81bed5ab33
commit 8f707f4cdb

View File

@ -54,11 +54,19 @@ strbuf strbuf_ncat(strbuf sb, const char *text, size_t len)
strbuf strbuf_puts(strbuf sb, const char *text) strbuf strbuf_puts(strbuf sb, const char *text)
{ {
if (sb->start && (!sb->end || sb->current < sb->end)) { if (sb->start) {
register size_t n = sb->end ? sb->end - sb->current : -1; if (!sb->end) {
while (n-- && (*sb->current = *text)) { while ((*sb->current = *text)) {
++sb->current; ++sb->current;
++text; ++text;
}
} else if (sb->current < sb->end) {
register size_t n = sb->end - sb->current;
while (n-- && (*sb->current = *text)) {
++sb->current;
++text;
}
*sb->current = '\0';
} }
} }
while (*text++) while (*text++)