From: Tom White Subject: Possible read() bug? To: djgpp AT sun DOT soe DOT clarkson DOT edu Date: Fri, 27 May 1994 04:22:09 -0400 (EDT) I'm programming with 1.11.maint5 from DOS with no DPMI services. I have spent many hours tracking down what appears to be the following bug: if read() is called on to read into an array that has not yet been referenced, random variables get clobbered. Here's sort of what my code looks like: unsigned char buffer[50][2000]; int length; [...] void ReadFile(void) { int handle, i; handle = open("FILENAME.ABC", O_RDONLY | O_BINARY); read(handle, &length, sizeof(int)); for(i=length; i>0; i--) read(handle, buffer[i], 2000); close(handle); } Now if I call the function ReadFile without using buffer beforehand, everything works except that length gets completely clobbered. gdb and exhaustive printfs tell me that length is clobbered only the first time through the loop in the read statement. But if I first call some other stupid initalizing procedure like: void InitBuffer(void) { int i,j; for(i=0;i<50;i++) for(j=0;j<2000;j++) buffer[i][j] = i+j; } Then ReadFile() works just dandy and doesn't touch my other globals. So is this a bug or am I up too late? I have a hard time believing that something this critical could go unnoticed for long - so if I have some C to learn, please be kind. :) -Tom -- =========================================================== Tom White white AT cs DOT uga DOT edu ===========================================================