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:
The compiler does what it feels like doing. Or what the developer(s) who write the compiler felt like doing, depending on whether the compiler is sentient or not.
This may include:
The C standard does not specify anything about the order in memory of unrelated objects. Compilers do whatever makes sense to their programmers.