Browse Source

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 years ago
parent
commit
6af59d0d23
2 changed files with 1 additions and 1 deletions
  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;
 		return -1;
 	}
 	}
 	rv = vfprintf(f, format, arg);
 	rv = vfprintf(f, format, arg);
-	if (rv >= 0) fputc('\0', f);
 	fclose(f);
 	fclose(f);
 	if (rv < 0) {
 	if (rv < 0) {
 		free(*buf);
 		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) {
 	if (COOKIE->pos > COOKIE->eof) {
 		*COOKIE->sizeloc = COOKIE->eof = COOKIE->pos;
 		*COOKIE->sizeloc = COOKIE->eof = COOKIE->pos;
+		COOKIE->buf[COOKIE->eof] = 0; /* Need to nul-terminate. */
 	}
 	}
 
 
 	return bufsize;
 	return bufsize;