title: Valgrind Invalid read size of 1
body: <p>For the life of me i cant work out why I am getting an <code>invalid read size of 1</code> for this code snippet, I'm pretty sure its got something to do with me abusing the <code>char *url pointer</code>...</p>
  
  <pre><code>char *extractURL(char request[])
  {
  char *space = malloc(sizeof(char *));
  space = strchr(request, ' ')+1;
  char *hostend = malloc(sizeof(char *));
  hostend = strchr(request, '\r');
  int length = hostend - space;
  if (length &gt; 0)
  {
      printf("Mallocing %d bytes for url\n.", length+1);
      char *url = (char *)malloc((length+1)*sizeof(char));
      url = '\0';
      strncat(url, space, length);
      return url;
  }
  //else we have hit an error so return NULL
  return NULL;    
  }
  </code></pre>
  
  <p>The valgrind error I am getting is :</p>
  
  <pre><code>==4156== Invalid read of size 1
  
  ==4156==    at 0x4007518: strncat (mc_replace_strmem.c:206)
  
  ==4156==    by 0x8048D25: extractURL ()
  
  ==4156==    by 0x8048E59: processRequest ()
  
  ==4156==    by 0x8049881: main ()
  
  ==4156==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
  </code></pre>
  
  <p>Can someone 'point' me in the right direction?</p>