Fix bug in strbuf_ncat(): not appending nul terminator

This commit is contained in:
Andrew Bettison 2012-08-03 13:11:30 +09:30
parent 0022990e72
commit 355af1f874

View File

@ -46,8 +46,9 @@ strbuf strbuf_ncat(strbuf sb, const char *text, size_t len)
if (sb->start && sb->current < sb->end) {
register size_t n = min(sb->end - sb->current, len);
char *c;
for (c = sb->current; n-- && (*c = *text); ++c, ++text)
for (c = sb->current; n && (*c = *text); --n, ++c, ++text)
;
*c = '\0';
}
sb->current += len;
return sb;