From: SF/projects/mingw n. l. <min...@li...> - 2012-03-12 06:44:24
|
Bugs item #3502385, was opened at 2012-03-11 23:44 Message generated for change (Tracker Item Submitted) made by veiokej You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=3502385&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: MinGW Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Veiokej (veiokej) Assigned to: Nobody/Anonymous (nobody) Summary: fread() can't read 0x3FF8000 bytes Initial Comment: I've seen this bug multiple times, across WinXP reinstalls. I can never read more than 0x3FF7FFF bytes in a single fread(). That's a really weird limint, since it's an odd number. So if nothing else, it looks like something is off-by-one. Fundamentally, why is this the case? It shouldn't take much memory to read (apart from the buffer that the caller has already allocated). This number does kind of look like some memory or data structure limit has been exhausted, in particular, some nice and round looking arbitrary limit that someone established without regard for the OS context. Granted, this could be a WinXP issue, but I have 2GB of memory. Any clues? This is annoying because it prevents me from writing code that processes whole files with a single fread(). Perhaps if the bug is in fact in MinGW, then it would affect the MinGW64 project as well. If you create a test.bin file of more than this many bytes (say, 64MiB), then you can see the bug with this C code, assuming that it happens in your particular configuration: #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define READ_SIZE (0x3FF8000) int main(int argc, char *argv[]){ char *string_base; FILE *handle; size_t transfer_size; string_base=malloc((size_t)(READ_SIZE)); if(string_base==NULL){ printf("No memory.\n"); exit(0); } handle=fopen("test.bin","rb"); if(handle){ printf("expected transfer_size=0x%08X\n",READ_SIZE); transfer_size=fread(string_base,(size_t)(1),(size_t)(READ_SIZE),handle); printf("transfer_size=0x%08X\n",transfer_size); fclose(handle); }else{ printf("Please create a random test.bin of size > 2^26 first.\n"); } return 0; } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=3502385&group_id=2435 |