title: Linux malloc segmentation fault missing
body: <p>The included program should produce a segmentation fault in Linux, but it doesn't:
  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  /* This program should produce a segmentation error */
  /* but it doesn't */
  
  /* Therefore memory bounds are not being checked by the kernel */
  
  typedef struct {
     double x;
  } blkfmt;
  
  int main()
  {
     blkfmt *blk;
     unsigned char *p;
     blk = (blkfmt *) malloc(sizeof(blkfmt));
     p = (unsigned char *) blk + 16384;
     /* this assignment should produce a segmentation error */
     *p = (unsigned char) 0xff;
     /* this print statement should produce a segmentation error */
     printf("%02x %d\n", *p, sizeof(blkfmt));
     free(blk);
     return(0);
  } /* main */
  </code></pre>
  
  <h2>makefile:</h2>
  
  <pre class="lang-make prettyprint-override"><code>OBJ=bug.o    
  CC=gcc
  CFLAGS=-c -Wall -O2
  LDFLAGS=
  
  bug:                $(OBJ)
          $(CC) -Wall -O2 $(OBJ) -o bug $(LDFLAGS)
  
  bug.o:              bug.c
          $(CC) $(CFLAGS) bug.c
  
  clean:
          rm -f bug $(OBJ)
  </code></pre>