提交 d2e061a2 编写于 作者: R Rich Felker

more fmemopen null termination fixes

null termination is only added when current size grows.
in update modes, null termination is not added if it does not fit
(i.e. it is not allowed to clobber data).

these rules make very little sense, but that's how it goes..
上级 e72ee578
......@@ -54,9 +54,10 @@ static size_t mwrite(FILE *f, const unsigned char *buf, size_t len)
if (len > rem) len = rem;
memcpy(c->buf+c->pos, buf, len);
c->pos += len;
if (c->pos >= c->len) {
if (c->pos > c->len) {
c->len = c->pos;
c->buf[c->len==c->size ? c->len-1 : c->len] = 0;
if (c->len < c->size) c->buf[c->len] = 0;
else if ((f->flags&F_NORD) && c->size) c->buf[c->size-1] = 0;
}
return len;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册