Friday, 15 March 2013

why is gcc allocating more space to char buffer -



why is gcc allocating more space to char buffer -

i kind of confused latest version of gcc. simple piece of code compiled:

int main() { char buffer[1]; scanf("%s",buffer); printf("you entered %s\n", buffer ); homecoming 0; }

when dissemble func, find :

(gdb) disas main dump of assembler code function main: 0x0804846d <+0>: force %ebp 0x0804846e <+1>: mov %esp,%ebp 0x08048470 <+3>: , $0xfffffff0,%esp 0x08048473 <+6>: sub $0x20,%esp 0x08048476 <+9>: lea 0x1f(%esp),%eax 0x0804847a <+13>: mov %eax,0x4(%esp) ...........................

my question why subtract 0x20 i.e 32 bytes, when allocate 1 byte ! dont understand unusual behaviour

p.s. studying buffer overflows problem doesnt seem related it,still fyi had turned aslr off , other gcc stack protection stuff.

gcc buffer-overflow

No comments:

Post a Comment