瀏覽代碼

fix swprintf handling of nul character in output

the buffer-flush function did not account for mbtowc returning 0
rather than 1 when converting the nul character. this prevented
advancing past it, instead repeatedly converting it into the output
wide character string until the max output length was exhausted.
Rich Felker 2 年之前
父節點
當前提交
1d5750b95c
共有 1 個文件被更改,包括 1 次插入0 次删除
  1. 1 0
      src/stdio/vswprintf.c

+ 1 - 0
src/stdio/vswprintf.c

@@ -18,6 +18,7 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
 	if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1)
 		return -1;
 	while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) {
+		if (!i) i=1;
 		s+=i;
 		l-=i;
 		c->l--;