Skip to content

Fix two bugs in fwrite() and fread() - #157

Open
rosenrost wants to merge 2 commits into
freemint:masterfrom
rosenrost:fix/always-write-to-the-end-of-the-file-in-append-mode
Open

rosenrost wants to merge 2 commits into
freemint:masterfrom
rosenrost:fix/always-write-to-the-end-of-the-file-in-append-mode

Conversation

@rosenrost

Copy link
Copy Markdown
Contributor
  1. Streams opened with "a" or "a+" only seeked to the end of the file once in fopen(). After an fseek() or reading in "a+" mode, data was written into the middle of the file.

  2. fread() and fwrite() divided the number of transferred bytes by size to compute the number of items, which crashed with a division by zero when called with size == 0.

Both functions divided the number of transferred bytes by size to
compute the number of items, which crashed with a division by zero
when called with size == 0. Return 0 early if size or nmemb is 0,
as required by the C standard.
Streams opened with "a" or "a+" only seeked to the end of the file
once in fopen(). After an fseek() or reading in "a+" mode, data was
written into the middle of the file. fwrite() now moves to the end of
the file before every write of an append mode stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant