Fix bug in strbuf_reset()

Could write a nul char into a zero-size buffer.
This commit is contained in:
Andrew Bettison 2015-11-17 00:13:22 +10:30
parent 23cd578595
commit fc67b38fd2

View File

@ -35,8 +35,8 @@ strbuf strbuf_init(strbuf sb, char *buffer, ssize_t size)
strbuf strbuf_reset(strbuf sb) strbuf strbuf_reset(strbuf sb)
{ {
sb->current = sb->start; sb->current = sb->start;
if (sb->start) if (sb->current && (!sb->end || (sb->current <= sb->end)))
*sb->start = '\0'; *sb->current = '\0';
return sb; return sb;
} }