浏览代码

Revert Erik's patch to vasprintf and fix the real issue.
The writer for the stream returned by open_memstream was supposed to
keep the buffer nul-terminated. I apparently left out a statement.

Manuel Novoa III 23 年之前
父节点
当前提交
6af59d0d23
共有 2 个文件被更改,包括 1 次插入1 次删除
  1. 0 1
      libc/stdio/printf.c
  2. 1 0
      libc/stdio/stdio.c

+ 0 - 1
libc/stdio/printf.c

@@ -1451,7 +1451,6 @@ int vasprintf(char **__restrict buf, const char * __restrict format,
 		return -1;
 	}
 	rv = vfprintf(f, format, arg);
-	if (rv >= 0) fputc('\0', f);
 	fclose(f);
 	if (rv < 0) {
 		free(*buf);

+ 1 - 0
libc/stdio/stdio.c

@@ -643,6 +643,7 @@ static ssize_t oms_write(void *cookie, const char *buf, size_t bufsize)
 
 	if (COOKIE->pos > COOKIE->eof) {
 		*COOKIE->sizeloc = COOKIE->eof = COOKIE->pos;
+		COOKIE->buf[COOKIE->eof] = 0; /* Need to nul-terminate. */
 	}
 
 	return bufsize;