ref: 239fa3156f2766158945882883bf00ef8f342ea8
parent: 65014a8ce3a1b7d2b18c97bca389d17d83faff57
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Sep 1 10:22:20 EDT 2018
[lib/c] Fix _flsbuf() This function couldn't work if the buffer pointers were not initialized.
--- a/lib/c/_flsbuf.c
+++ b/lib/c/_flsbuf.c
@@ -7,9 +7,11 @@
_flsbuf(FILE *fp)
{
int lnbuf = fp->flags & _IOLBF;
+ unsigned char *p;
size_t cnt;
- cnt = ((lnbuf) ? fp->lp : fp->wp) - fp->buf;
+ p = (lnbuf) ? fp->lp : fp->wp;
+ cnt = p - fp->buf;
if (_write(fp->fd, fp->buf, cnt) != cnt) {
fp->flags |= _IOERR;
--- a/lib/c/stdio.c
+++ b/lib/c/stdio.c
@@ -9,13 +9,19 @@
.fd = 0,
.buf = inbuf,
.len = BUFSIZ,
- .flags = _IOREAD
+ .flags = _IOREAD,
+ .lp = inbuf,
+ .rp = inbuf,
+ .wp = inbuf,
},
{
.fd = 1,
.buf = outbuf,
.len = BUFSIZ,
- .flags = _IOWRITE | _IOLBF
+ .flags = _IOWRITE | _IOLBF,
+ .lp = outbuf,
+ .rp = outbuf,
+ .wp = outbuf,
},
{
.fd = 2,