This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nneonneo
Recipients benjamin.peterson, nneonneo, pitrou, pmpp
Date 2010-01-30.23:40:19
SpamBayes Score 1.3267165e-14
Marked as misclassified No
Message-id <1264894821.86.0.655015799362.issue5677@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-01-30 23:40:21nneonneosetrecipients: + nneonneo, pitrou, benjamin.peterson, pmpp
2010-01-30 23:40:21nneonneosetmessageid: <1264894821.86.0.655015799362.issue5677@psf.upfronthosting.co.za>
2010-01-30 23:40:20nneonneolinkissue5677 messages
2010-01-30 23:40:19nneonneocreate