Re: accessing freed memory without error
From: bd (bdonlan_at_gmail.com)
Date: 01/17/05
- Next message: imanpreet_at_gmail.com: "Re: Do buffers always start with the lowest memory address being the first element?"
- Previous message: bd: "Re: Implemenation Indepdent Way to Move LSByte of Char to MSB of Int, etc"
- In reply to: sachin_mzn_at_yahoo.com: "accessing freed memory without error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 Jan 2005 15:01:53 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
sachin_mzn@yahoo.com wrote:
> Hi,
>
> Why I am not getting any run time error while accessing a freed memory
> in following code. This is printing h in std output.
>
> #include<stdio.h>
> main()
> {
> char* buffer = (char*)malloc(6);
> strcpy(buffer,"hello");
> free(buffer);
> printf("buffer=%c\n", *buffer);
> }
The effects of accessing freed memory are undefined. This means anything can
happen, including nothing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFB7Bmx+hz2VlChukwRAuvUAKC0oI2YJBXOxsWO4rAzSqwer8/YtQCfVBfR
lIVTC8MC9YidBIuG9GPcErg=
=TQbd
-----END PGP SIGNATURE-----
- Next message: imanpreet_at_gmail.com: "Re: Do buffers always start with the lowest memory address being the first element?"
- Previous message: bd: "Re: Implemenation Indepdent Way to Move LSByte of Char to MSB of Int, etc"
- In reply to: sachin_mzn_at_yahoo.com: "accessing freed memory without error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|