title: Segmentation fault with 3-dimensional malloc'ed array
body: <p>When I C code compile and exit, I get a segmentation fault. When I tried to run GDB, the result is as follows:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x0000000000400998 in main (argc=2, argv=0x7fffffffe208) at test.c:107
  </code></pre>
  
  <p>The line in question:</p>
  
  <pre><code>if((p_l2p[p_bp][p_rp][p_cp] &amp; FULL) == 0)
  </code></pre>
  
  <p>The variable declaration:</p>
  
  <pre><code>unsigned long long ***p_l2p; //Primary L2P[P_Bank][Row][Cas]
  p_l2p = (unsigned long long ***)malloc(sizeof(int **)*P_BANK);
  
  for(i=0;i&lt;P_BANK;i++) // set s[P_Bank][Row]
  {
      p_l2p[i] = (unsigned long long **)malloc(sizeof(int*)*ROW);         
  
      for(j=0;j&lt;ROW;j++) // set s[P_Bank][Row][CAS]
      {
          p_l2p[i][j] = (unsigned long long *)malloc(sizeof(int)*CAS);
  
      }
  }
  
  int p_bp; //Bank Point
  int p_rp; //Row Point
  int p_cp; //Cas Point
  </code></pre>
  
  <p>(Note that the P_BANK value is 4, the ROW value is 8192, and the Column value is 128.)</p>
  
  <p>The problem is when I try to print the point where the segmentation fault is through GDB as below.
  (We confirmed that the value causing the segment fault is p_l2p [2] [15] [80].)</p>
  
  <p>The point where the segment fault is p_l2p [2] [15] [80] is one of the arrays declared as dynamic memory allocation by code. I tried to print those variables using GDB's print function. Oddly, there are values ​​of p_l2p [2] [14] [x] and p_l2p [2] [16] [x], but only values ​​corresponding to p_l2p [2] [15] [x] do not exist.</p>
  
  <p>What is the cause of this segmentation fault?</p>