Your best bet is to simply look at the assembler code of the function and find out what it's doing with the areas offset from esp
and ebp
(depending on your calling convention).
It may be using them for various temporaries, for example. Or it may be pre-allocating the space for parameters to be sent to gets
and/or printf
. Or it may be trying to align the stack pointer to some "resolution", for example, easing SSE object alignments.
Or it may be recognising that people who use gets
tend to not understand the dangers of buffer overruns, and it's giving you a small amount of extra room as breathing space :-)
Bottom line, we can't tell without seeing what the compiler has generated. Even with that information, however, it may not be obvious as to why the compiler allocates more than requested, since we may still be working with incomplete information.
Based on your added assembler dump, the buffer for gets
and printf
(which has sneakily been optimised to puts
) is eighteen bytes above the stack pointer and there's no immediate use made of the intervening area.
So, unless gets/puts
use it for something (unlikely) or the procedure linkage table does (still unlikely but it's a convoluted beast), you may just have to assume it's overkill or alignment requirements for your platform, generated from the compiler.
You could of course test it with various array sizes to see how that affects the space allocated. That's likely to at least give some extra information which may make a theory more viable.
Based on your comment that char[15]
allocates 0x28
and char[16]
allocates 0x38
, that seems to be a 16-byte alignment requirement for the stack pointer (it ends with an 8
because there are eight bytes already used as part of the call: the return address itself, and the previous ebx
).
And, indeed, if you search the web for gcc 16 byte alignment stack pointer
, you'll find some very spirited discussion as to whether gcc
is doing the right thing here but, amongst all that discussion is the basic fact that gcc
does align the stack to 16 bytes (rightly or wrongly).