public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/1996] New: open_memstream() and seek past end of buffer
@ 2005-12-08 15:33 michael dot kerrisk at gmx dot net
  2006-04-24 22:05 ` [Bug libc/1996] " rsa at us dot ibm dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: michael dot kerrisk at gmx dot net @ 2005-12-08 15:33 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-14 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-08 15:33 [Bug libc/1996] New: open_memstream() and seek past end of buffer michael dot kerrisk at gmx dot net
2006-04-24 22:05 ` [Bug libc/1996] " rsa at us dot ibm dot com
2006-04-24 23:06 ` michael dot kerrisk at gmx dot net
2006-04-25 21:22 ` rsa at us dot ibm dot com
2006-08-14 22:16 ` drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).