title: "Bad permissions for mapped region at address" Valgrind error for a hash table
body: <p>I'm pretty new to C. When I run the following code for a hash table under Valgrind:</p>
  
  <pre><code>table *insertObject (table *h, int pref, char ch)
  {
      struct node x;
      int i;
      if (ch &lt; 0)
      {
          ch=256-ch;
      }
      x.chr=ch;
      x.pref=pref;
      i = hash(pref, ch, h-&gt;size);
      while (h-&gt;hash[i].pref!=0)
      {
          i++;
      }
      h-&gt;hash[i]=x;
      h-&gt;size++;
      return h;
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>==9243== 
  ==9243== Process terminating with default action of signal 11 (SIGSEGV)
  ==9243==  Bad permissions for mapped region at address 0x6018A4
  ==9243==    at 0x4009CD: insertObject (encode.c:119)
  ==9243==    by 0x4008E3: main (encode.c:55)
  </code></pre>
  
  <p>Line 119 is the line</p>
  
  <pre><code> h-&gt;hash[i]=x;
  </code></pre>
  
  <p>The funny thing is, when I run the whole code through a debugger, it works fine 90% of the time. However, for some special cases, the code segfaults, and the debugger tells me this is also the culprit. What's wrong?</p>