Robert Xiao <[email protected]> added the comment:
It seems like this is actually a problem in Windows libc or something (tested
using MinGW on Windows XP):
#include <stdio.h>
main() {
FILE *f = fopen("test", "wb");
fwrite("test", 1, 4, f);
char buf[2048];
size_t k = fread(buf, 1, 2048, f);
printf("%d\n", k);
int i=0;
for(; i<k; i++) printf("%02x", buf[i]);
}
This causes a lot of garbage to be printed out. Removing the fwrite causes "0"
to be printed with no further output.
The garbage is not from the uninitialized buffer, since I've verified that the
original contents of the buffer are not what is being printed out. Furthermore,
adjusting 2048 produces a maximum output of 4092 bytes (even with 9999 in place
of 2048).
Short of simply denying read() on writable files, I don't really see an easy
way around this libc bug.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue5677>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com