title: invalid write size of 1 in C
body: <p>I trying to write a queue(String Version) program in C by using linked lists.</p>
  
  <p>Here is the structure:</p>
  
  <pre><code>struct strqueue;
  typedef struct strqueue *StrQueue;
  
  struct node {
    char *item;
    struct node *next;
  };
  
  struct strqueue {
    struct node *front;//first element
    struct node *back;//last element in the list
    int length;
  };
  </code></pre>
  
  <p>I creates a new StrQueue first</p>
  
  <pre><code>StrQueue create_StrQueue(void) {
    StrQueue q = malloc(sizeof (struct strqueue));
    q-&gt;front = NULL;
    q-&gt;back = NULL;
    q-&gt;length = 0;
    return q;
  }
  </code></pre>
  
  <p>makes a copy of str and places it at the end of the queue</p>
  
  <pre><code>void push(StrQueue sq, const char *str) {
    struct node *new = malloc(sizeof(struct node));
    new-&gt;item = NULL;
    strcpy(new-&gt;item,str);//invalid write size of 1 ?
    new-&gt;next = NULL;
    if (sq-&gt;length == 0) {
    sq-&gt;front = new;
    sq-&gt;back = new;
  } else {
    sq-&gt;back-&gt;next = new;
    sq-&gt;back = new;
  }
  sq-&gt;length++;
  }
  </code></pre>
  
  <p>frees the node at the front of the sq and returns the string that was first in the queue</p>
  
  <pre><code>char *pop(StrQueue sq) {
   if (sq-&gt;length == 0) {
   return NULL;
  }
   struct node *i = sq-&gt;front;
   char *new = sq-&gt;front-&gt;item;
   sq-&gt;front = i-&gt;next;
   sq-&gt;length --;
   free(sq-&gt;front);
   return new;
  }
  </code></pre>
  
  <p>I got invalid write size of 1 at strcpy(new->item,str); I dont understand why I got this error.
  Can anyone tell me why and tell me how should I fix it? Thanks in advance.</p>