Find   


An Affiliate of AIHorizon




This tip submitted by Bhushan Verma on 2005-10-19 03:17:26. It has been viewed 26031 times.
Rating of 3.3226 with 93 votes

Be careful about array size when u are using strcp



Array/Buffer Overflow

If we copy or insert data more into an array of limited size, it is referred as array overflow.
Look at the following code:


char var1[10];
char var2[7] = \"bhushan\"; /* '\0' is not added ,as size is given as 7*/
strcpy( var1, var2 );

Here, we can find that var2 (“bhushan”) is not terminated with a Null terminator (‘\0’). So when we copy var2 to var1 using strcpy( ), the strcpy( ) routine will copy all the character to var2 until it finds ‘\0’ in memory. So array overflow may result in memory overwrite!





More tips


Add a tip!



-----
Interested in advertising with us?
Please read our privacy policy.
Copyright © 1997-2005 Cprogramming.com. All rights reserved.