Sumit Chawla wrote:
> On 07 Mar 2007 18:36:56 -0800, Chetan Nanda <[EMAIL PROTECTED]> wrote:
>> Hi All,
>> Acn anybody explain me the behavior of the following program.
>>
>> #include <stdio.h>
>> int main()
>> {
>>     char *dst = (char *) malloc(4);
>>     strcpy(dst, "This is a nice palace");
>>
>>      exit(0);
>> }
>>
>> This is a clear case of memory corruption. But it do not crash. I am using
>> GCC as compiler.
>>
>> ~nandac
>>
> 
> You are crossing the memory bounds and corrupting the memory block which
> might have  been allocated to other parts of your program or some other
> program. It might crash the other programs or applications. So behavior is
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> undefined.

Not on any modern OS (Windows, Linux, BSD, Mac OSX - BSD variant) that 
I'm aware of that segments address space into pages and maps physical 
memory pages to virtual addresses.  You might see this on an embedded 
platform where the hardware doesn't support it, but not much anywhere else.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.2
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

Free for personal use, $10 otherwise.
http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to