title: segmentation fault with a game of life function
body: <p>I'm getting a segmentation fault in this function and I have no idea why. I can't isolate the problem with GDB, it just tells me this is the function that fails and I'm just looking to see if anyone sees something immediately wrong. I'm trying to learn C and optimize this function. It's a function for cell evolution for an implementations of Conway's game of life. </p>
  
  <p>I call two other functions within this one that return the number of neighbors a cell has. The board is a 2d array, of WIDTH and HEIGHT.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>void evolveCell(board prev, board next)
  {
    int i, j, n, mask;
     int width = WIDTH;
     int height = HEIGHT;
  
   for (i=1; i &lt; width-1; ++i) {
        for (j = 1; j &lt; height-1; ++j) {
           n = _neighbors(prev, i, j);
           mask = (prev[i][j] &lt;&lt; 1);
           next[i][j] = !(((n &gt;&gt; prev[i][j]) ^ 3) ^ mask);
        }
     }
  
     for (i = 0; i &lt; width; i+= width-1) {
       prev[i][j] = prev[i][0];
       next[i][j] = next[i][0];
       for (j = 0; j &lt; height; ++j) {
         n = neighbors(prev, i, j);
         mask = (prev[i][j] &lt;&lt; 1);
         next[i][j] = !(((n &gt;&gt; prev[i][j]) ^ 3) ^ mask);
       }
     }
     for (j = 0; j &lt; height; j += height-1) {
       prev[i][j] = prev[0][j];
       next[i][j] = next[0][j];
       for (i = 0; i &lt; width; ++i) {
         n = neighbors(prev, i, j);
         mask = (prev[i][j] &lt;&lt; 1);
         next[i][j] = !(((n &gt;&gt; prev[i][j]) ^ 3) ^ mask);
       }
     }
  </code></pre>
  
  <p>}</p>