This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/17063] New: fclose() may fail to flush data
- From: "ppluzhnikov at google dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Tue, 17 Jun 2014 17:35:39 +0000
- Subject: [Bug stdio/17063] New: fclose() may fail to flush data
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=17063
Bug ID: 17063
Summary: fclose() may fail to flush data
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: stdio
Assignee: unassigned at sourceware dot org
Reporter: ppluzhnikov at google dot com
This is a followup to PR16532.
A program that does
fopen(..., "w+");
fwrite(...);
fread(...);
fclose();
may leave empty file on disk (fail to flush when it should have), when the
fread requests more than a page's worth of data.
At least glibc-2.19 through current trunk
(754c5a08aacb44895d1ab97c553ce424eb43f761) are affected.
./t
testing 3
testing 3 OK
testing 6
testing 6 OK
testing 9
testing 9 OK
testing 4095
testing 4095 OK
testing 4096
t: t.c:28: do_test: Assertion `pos == 6' failed.
Aborted
/// --- cut ---
#include <assert.h>
#include <stdio.h>
void do_test (int n)
{
FILE *fp;
const char *const fname = "/tmp/output";
int nwritten, nread, pos;
char line[8192];
printf ("testing %5d\n", n);
fp = fopen (fname, "w+");
nwritten = fwrite ("abcabc", 1, 6, fp);
assert (nwritten == 6);
pos = ftello (fp);
assert (pos == 6);
nread = fread (line, 1, n, fp);
assert (nread == 0);
fclose (fp);
fp = fopen (fname, "r");
fseeko (fp, 0, SEEK_END);
pos = ftello (fp);
assert (pos == 6);
printf ("testing %5d OK\n", n);
}
int main(int argc, char *argv[])
{
int j, nreads[] = { 3, 6, 9, 4095, 4096, 4097, 8191, 8192 };
for (j = 0; j < sizeof (nreads) / sizeof (nreads[0]); ++j)
do_test (nreads[j]);
return 0;
}
--
You are receiving this mail because:
You are on the CC list for the bug.