Reputation: 4869
I have an buffer of size 101
char buffer[101]
I am trying to copy an address to the array
int i;
for(i=0;i<sizeof(buffer);i+=4)
*(long*)&buffer[i] = address
in which address is of type long.
However I met with a stack smashing detection when I am running it. Any idea why?
Upvotes: 0
Views: 73
Reputation: 183873
Alignment issues aside,
for(i=0;i<sizeof(buffer);i+=4)
*(long*)&buffer[i] = address
when i == 100
you write past the allocated buffer. You should stop when i > sizeof buffer - 4
.
Upvotes: 6