title: Segmentation fault: 11 in C when two dimension array's width > length
body: <p>I write some code in <code>C</code></p>
  
  <pre><code>#include &lt;stdlib.h&gt; 
  #include &lt;stdio.h&gt;
  
  int width=3,height=6;
  //if width&gt;height, the programe will crash
  
  void test(int ** input){
      printf("test value:\n\n");
      for(int i=0;i&lt;width;i++){
          for(int j=0;j&lt;height;j++)
              printf("%dx%d=%d\t",i,j,input[i][j]);
          printf("\n");
      }
  }
  
  int main()
  {
      int **p = (int**)malloc(sizeof(int*)*width); //for rows
      for(int i = 0; i &lt; height; i++)  
      {  
          *(p+i) = (int*)malloc(sizeof(int)*height);//for cols  
      }  
      for(int i =0;i&lt;width;i++)
          for(int j=0;j&lt;height;j++)
              p[i][j]=i*j;
  
      test(p);
      return 0;
  }
  </code></pre>
  
  <p><p>
  run it: 
  <code>gcc test.c &amp;&amp; a.out</code>
  Nothing is wrong, everything is OK.
  But, if i change <code>width=7</code> at line 4. The code will crash:
  </p><code>Segmentation fault: 11</code></p>
  
  <h2>Why?</h2>
  
  <p>I run it in:</p>
  
  <pre><code>zenith@zenithdeMacBook-Air:/ramdisk$ uname -a
  Darwin bogon 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun  3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
  zenith@zenithdeMacBook-Air:/ramdisk$ gcc -v
  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  Target: x86_64-apple-darwin13.3.0
  Thread model: posix
  </code></pre>