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/20005] fflush on a file opened with fmemopen resets position to 0


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

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  f9123b5003e62b6e54996076e860f23aee9a0593 (commit)
      from  085bbece2c6afc5f13698b52fac0299445c4317f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f9123b5003e62b6e54996076e860f23aee9a0593

commit f9123b5003e62b6e54996076e860f23aee9a0593
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Apr 26 17:40:25 2016 -0300

    libio: Update internal fmemopen position after write (BZ #20005)

    Current GLIBC fmemopen fails with a simple testcase:

      char buffer[500] = "x";
      FILE *stream;
      stream = fmemopen(buffer, 500, "r+");
      fwrite("fish",sizeof(char),5,stream);
      printf("pos-1:%ld\n",ftell(stream));
      fflush(stream);
      printf("pos-2:%ld\n",ftell(stream));

    It returns:

      pos-1:5
      pos-2:0

    Where it should return:

      pos-1:5
      pos-2:5

    This is due the internal write function does not correctly update the
internal
    object position state and then the seek operation returns a wrong value. 
This
    patch fixes it.

    It fixes both BZ #20005 and BZ #19230 (marked as duplicated). A new test is
    added to check for such case.

    Tested on x86_64 and i686.

        * libio/fmemopen.c (fmemopen_write): Update internal position after
        write.
        * stdio-common/Makefile (tests): Add tst-fmemopen4.c.
        * stdio-common/tst-fmemopen4.c: New file..

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |    8 ++++
 libio/fmemopen.c                                   |    6 +-
 stdio-common/Makefile                              |    2 +-
 .../tst-rwlock13.c => stdio-common/tst-fmemopen4.c |   41 ++++++++++----------
 4 files changed, 33 insertions(+), 24 deletions(-)
 copy nptl/tst-rwlock13.c => stdio-common/tst-fmemopen4.c (53%)

-- 
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]