Bug 6719 - setvbuf set _IOFBF incorrectly
Summary: setvbuf set _IOFBF incorrectly
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-04 10:07 UTC by Wang Xin
Modified: 2014-07-04 05:52 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wang Xin 2008-07-04 10:07:37 UTC
When a file was first open as NON BUFFERED, 
and then we change it into FULL BUFFERED, this will take no effect.

Following code will reproduce this bug.

#include <stdio.h>

int main(void)
{
    if (setvbuf(stderr, NULL, _IOFBF, BUFSIZ) != 0)
        printf("Set full buffer error.\n");

    fprintf(stderr, "Output #1 <stderr>.\n");
    printf("Output #2 <stdout>.\n");

    return 0;
}

If stderr is FULL BUFFERED after setvbuf, then Output #2 will display first.
But we can see Output #1 will display before #2.

And following patch maybe helpful.

--- iosetvbuf-old.c     2003-08-30 03:58:27.000000000 +0800
+++ glibc-2.7/libio/iosetvbuf.c 2008-07-04 15:48:48.000000000 +0800
@@ -45,7 +45,7 @@
   switch (mode)
     {
     case _IOFBF:
-      fp->_IO_file_flags &= ~_IO_LINE_BUF|_IO_UNBUFFERED;
+      fp->_IO_file_flags &= ~(_IO_LINE_BUF|_IO_UNBUFFERED);
       if (buf == NULL)
 	{
 	  if (fp->_IO_buf_base == NULL)
Comment 1 Ulrich Drepper 2008-07-08 16:33:00 UTC
Fixed in cvs.