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 libc/1996] New: open_memstream() and seek past end of buffer


The info page for open_memstream() says:

     You can move the stream's file position with `fseek' or `fseeko'
     (*note File Positioning::).  Moving the file position past the end
     of the data already written fills the intervening space with
     zeroes.

However, this is not so.  When the program below is run, the
following output is produced:

    $ ./a.out
    ftell() before = 0
    fseek error: Success
    ftell() after = 0
    ptr=0x804a180  size=3

Either the implementation or the documentation appears to be broken.


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

int main(int argc, char *argv[])
{
    FILE *output;
    size_t size;
    char *ptr;
    long l;

    output = open_memstream(&ptr, &size);
    assert(output != NULL);

    printf("ftell() before = %ld\n", ftell(output));
    l = fseek(output, 50, SEEK_END);
    if (l != 0) perror("fseek error");
    printf("ftell() after = %ld\n", ftell(output));
    fprintf(output, "xxx");
    fflush(output);
    printf("ptr=%p  size=%ld\n", ptr, (long) size);
    return 0;
}

-- 
           Summary: open_memstream() and seek past end of buffer
           Product: glibc
           Version: 2.3.5
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: michael dot kerrisk at gmx dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=1996

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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