title: Buffer overflow - order of local variables on stack
body: <p>I'm quite confused about how the local variables are ordered on the stack. I understand, that (on Intel x86) the local variables are stored from higher to lower address as they go in the code. So it's clear, that this code:</p>
  
  <pre><code>int i = 0;
  char buffer[4];
  strcpy(buffer, "aaaaaaaaaaaaaaa");
  printf("%d", i);
  </code></pre>
  
  <p>produces something like this:</p>
  
  <pre><code>1633771873
  </code></pre>
  
  <p>The <code>i</code> variable was overwritten by the overflowed buffer.</p>
  
  <p>However, if I swap the first two lines:</p>
  
  <pre><code>char buffer[4];
  int i = 0;
  strcpy(buffer, "aaaaaaaaaaaaaaa");
  printf("%d", i);
  </code></pre>
  
  <p>the output is absolutely same.</p>
  
  <p>How is it possible? The <code>i</code>'s address is lower than the <code>buffer</code>'s one and so an overflow of the buffer should overwrite other data, but not <code>i</code>. Or am I missing something?</p>