2

As of 2.23 the glibc seems to have changed its behavior on an fflush of a stream created with fmemopen, in that it resets the position to 0. I saw in the change-log that a the implementation of fmemopen was updated to fix a bunch of bugs, but none of those bugs talk about this behavior, and to me it seems like an incorrect change. I've been trying to determine if this a new bug, or a correct fix. My own code relies on the old behavior and broke after I updated to Ubuntu 16.04 which comes with glibc 2.23. Anybody know anything about this?

Here's some sample code:

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));

On earlier versions (e.g. under ubuntu 5.10<) this would result in:

pos-1:5
pos-2:5

Now it returns:

pos-1:5
pos-2:0
zippy
  • 1,228
  • 10
  • 19
  • 1
    This sure looks like a regression to me, and a pretty serious one. `fflush()` should not cause the file position to revert to 0. And such a change *certainly* should not escape mention in the release notes if it is in fact intentional. I am currently running a much older glibc, but I confirm that it behaves as you describe older glibc to do. I would file a bug report if there isn't one already. – John Bollinger Apr 26 '16 at 18:45
  • 1
    Yah, it seems like a big issue to me too. Currently I'm on IRC#glibc talking with some of the maintainers there to confirm that it's a bug. – zippy Apr 26 '16 at 18:59

1 Answers1

3

It turns out to be a bug in 2.23. The bug was logged and has been fixed.

zippy
  • 1,228
  • 10
  • 19