musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/stdio/vswprintf.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016年11月07日 20:39:59 -0500
committerRich Felker <dalias@aerifal.cx>2016年11月07日 20:39:59 -0500
commit7442442ccc665641a8827177e8e7ed45bbbd6584 (patch)
tree1131612f9a89aeb7a15f809d1b358186bb02159d /src/stdio/vswprintf.c
parentbc1e7731cee963e422575f81048792f4d5db9641 (diff)
downloadmusl-7442442ccc665641a8827177e8e7ed45bbbd6584.tar.gz
fix swprintf internal buffer state and error handling
the swprintf write callback never reset its buffer pointers, so after its 256-byte buffer filled up, it would keep repeating those bytes over and over in the output until the destination buffer filled up. it also failed to set the error indicator for the stream on EILSEQ, potentially allowing output to continue after the error.
Diffstat (limited to 'src/stdio/vswprintf.c')
-rw-r--r--src/stdio/vswprintf.c 9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/stdio/vswprintf.c b/src/stdio/vswprintf.c
index 7d237bae..6eb2f6ac 100644
--- a/src/stdio/vswprintf.c
+++ b/src/stdio/vswprintf.c
@@ -24,7 +24,14 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
c->ws++;
}
*c->ws = 0;
- return i<0 ? i : l0;
+ if (i < 0) {
+ f->wpos = f->wbase = f->wend = 0;
+ f->flags |= F_ERR;
+ return i;
+ }
+ f->wend = f->buf + f->buf_size;
+ f->wpos = f->wbase = f->buf;
+ return l0;
}
int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap)
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月07日 17:29:55 +0000

AltStyle によって変換されたページ (->オリジナル) /