Date: Thu, 8 Jan 1998 11:00:39 +0200 (IST) From: Eli Zaretskii To: David Eberhard cc: djgpp AT delorie DOT com Subject: Re: problem with memory allocation (I think) In-Reply-To: <34B47DFA.E0D6D796@xmission.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 8 Jan 1998, David Eberhard wrote: > If I change the for loop so that it only loops 640*480/2 times, then > it works fine. Can anyone tell me what's going on? You are assuming that the size of an int is 2 bytes, but in DJGPP it is 4 bytes (32 bits), and thus your loop writes beyond the limits of the buffer you allocated. You should not do any assumptions like that; use the sizeof operator instead. The following line: > buffer = malloc(640 * 480 * 2); should have been written like this: buffer = (unsigned int *)malloc(640 * 480 * sizeof(int)); Also, please note that it is usually a bad idea to put a long into a buffere which was malloc'ed for int's, like you do: long i; unsigned int *buffer; ... buffer[i] = i; This works in DJGPP, since int and long are both 32-bit, but on other architectures it will crash.