Re: why dosent buffer gets overflowed
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Fri, 22 Aug 2008 05:45:16 +0000
raashid bhatt said:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(char *p)
{
char i[5];
strcpy(i, p);
Subject line: "why dosent buffer gets overflowed"
What makes you think the buffer isn't being overflowed?
}
int main(int argc, char **argv)
{
func("AAAAAAAAAA"); // i have supplied 2 X 5 char to it
Then you're trying to store more data in the array than it has room for,
and you don't provide any safeguards against that, so you're overflowing
that buffer, and the result is that the program exhibits undefined
behaviour - i.e. the rules of C don't tell you what will happen.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Prev by Date: Re: Why const without type compiles?
- Next by Date: Re: Why const without type compiles?
- Previous by thread: Why const without type compiles?
- Next by thread: Re: why dosent buffer gets overflowed
- Index(es):
Relevant Pages
|