简体   繁体   中英

Keep getting stack smashing error

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM