title: How dangerous is it to access an array out of bounds?
body: <p>How dangerous is accessing an array outside of its bounds (in C)? It can sometimes happen that I read from outside the array (I now understand I then access memory used by some other parts of my program or even beyond that) or I am trying to set a value to an index outside of the array. The program sometimes crashes, but sometimes just runs, only giving unexpected results. </p>
  
  <p>Now what I would like to know is, how dangerous is this really? If it damages my program, it is not so bad. If on the other hand it breaks something outside my program, because I somehow managed to access some totally unrelated memory, then it is very bad, I imagine.
  I read a lot of 'anything can happen', <a href="https://stackoverflow.com/questions/8313852/what-happens-if-my-pointer-crosses-the-array-bounds">'segmentation might be the least bad problem'</a>, 'your hard disk might turn pink and unicorns might be singing under your window', which is all nice, but what is really the danger?</p>
  
  <p>My questions:</p>
  
  <ol>
  <li>Can reading values from way outside the array damage anything
  apart from my program? I would imagine just looking at things does
  not change anything, or would it for instance change the 'last time
  opened' attribute of a file I happened to reach?</li>
  <li>Can setting values way out outside of the array damage anything apart from my
  program? From this
      <a href="https://stackoverflow.com/questions/671703/array-index-out-of-bound-in-c">Stack Overflow question</a> I gather that it is possible to access
      any memory location, that there is no safety guarantee.</li>
  <li>I now run my small programs from within XCode. Does that
  provide some extra protection around my program where it cannot
  reach outside its own memory? Can it harm XCode?</li>
  <li>Any recommendations on how to run my inherently buggy code safely?</li>
  </ol>
  
  <p>I use OSX 10.7, Xcode 4.6.</p>