This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/18659] New: libio: large read after a write fails to flush buffer


https://sourceware.org/bugzilla/show_bug.cgi?id=18659

            Bug ID: 18659
           Summary: libio: large read after a write fails to flush buffer
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: siddhesh at redhat dot com
          Reporter: siddhesh at redhat dot com
  Target Milestone: ---

When a program calls fread on a file immediately after writing a small amount
of data, it may fail to flush the written data if the read size is greater than
or equal to the FILE buffer size.  The following test demonstrates this:

#include <stdio.h>
#include <assert.h>

void main()
{
    FILE *f;
    char foo[4096];
    int n;

    f = fopen("/tmp/test", "a+"); /* qemu does fdopen */
    assert(f);
    fwrite("Hello World!\n", 1, 13, f);

    n = fread(foo, 1, READ_SIZE, f);
    fprintf(stderr, "eof?%d %d", feof(f), n);

    fseek(f, 0, SEEK_SET);
    n = fread(foo, 1, sizeof(foo), f);
    fprintf(stderr, "eof?%d %d", feof(f), n);
}

1) gcc test.c -DREAD_SIZE=4096 -o test (qemu-ga tries to read
QGA_READ_COUNT_DEFAULT=4096 by default)
./test
first read: 0
read after seek 0: 0

2) gcc test.c -DREAD_SIZE=13 -o test
./test
first read: 0
read after seek 0: 13

Patch coming up.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]