I am following a book where they explain about the buffer overflow. I have a question based on buffer overflow output in C. There are two char array(buffer_one[8] and buffer_two[8]) and one integer (value).
In a x86_64 system, I am declaring the variables in an order.
int value = 5;
char buffer_one[8], buffer_two[8];
However when i dump the address of these three variables, I received them in below order(value at d4, then buffer_one at d8 and then buffer_two at e0).
Buffer_one is at 0x7ffe7860b2d8 and contains one
Buffer_two is at 0x7ffe7860b2e0 and contains two
Value is at 0x7ffe7860b2d4 and contains 5
Same when I tried in a i686 system, I observed different order of memory allocation (buffer_two at 28, then buffer_one at 30 and then value at 38).
Buffer_one is at 0xbfef7330 and contains one
Buffer_two is at 0xbfef7328 and contains two
Value is at 0xbfef7338 and contains 5
MY QUESTIONS:
- Why the order of memory allocation differs despite being orderly declared?
- If I declare both char array before int, why int variable is always allocated before buffer_two in x86_64 system?
- What will be the order in ARM architecture?