title: C segfault with nested structure-pointer
body: <p>I am pretty new to C and trying to understand it better, but I occured some strange behavior, which I do not fully understand:
  I have this 2 structs:</p>
  <pre class="lang-c prettyprint-override"><code>typedef struct edge
  {
      int start_node;
      int end_node;
  } edge;
  
  
  typedef struct graph 
  {
      int node_count;
      edge *edges;
  } graph;
  </code></pre>
  <p>If I now initalize my graph (allocating the memory):</p>
  <pre class="lang-c prettyprint-override"><code>    graph *g = malloc((sizeof(edge )* (edge_amount)) + sizeof(int)); 
  </code></pre>
  <p>If I now try to initalize my edges like:
  (calling the function parse_graph(g-&gt;edges);)</p>
  <pre class="lang-c prettyprint-override"><code>void parse_graph(edge *edges){
   for (int i = 0; i &lt; edge_amount ; i++)
      {
        
  
          edge edge;
          edge.start_node = some int
          edge.end_node = some int
          edges[i] = edge;
      }
  }
  </code></pre>
  <p>I am getting a segfault in the edges[i] = edge line.
  But, when I initalize my graph (only the edges) like:</p>
  <pre class="lang-c prettyprint-override"><code> edge *g= malloc((sizeof(edge )* (edge_amount)) + sizeof(int));
  </code></pre>
  <p>And I call the function like parseInput(g), I do not get the segfault.
  I am sure I have forgot something important, but I can not figure it out. What I am missing here?</p>