title: How to fix 'read memory from 0x4000000000000000 failed (0 of 4 bytes read)' error in C
body: <p>I have a simple exercise to do on C. But when I initialize my variable graph with malloc, it do not perform the action correctly. Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  typedef int Weight;
  
  typedef struct aux {
      int vDest;
      Weight weight;
      struct aux * next;
  } TypeEdge;
  
  typedef TypeEdge* TypePointer;
  
  typedef struct {
      TypePointer * listAdj;
      int numVertices;
      int numEdges;
  } TypeGraph;
  
  typedef int* TipoInt;
  
  bool initializeGraph(TypeGraph *graph, int nv) {
      if (nv &lt; 0) {
          return false;
      }
  
      graph-&gt;numVertices = nv;
      graph-&gt;numEdges = 0;
      int i;
      for (i = 0; i &lt; nv; i++) {
          graph-&gt;listAdj = (TypePointer*) malloc(sizeof(TypePointer));
      }
      for (i = 0; i &lt; nv; i++) {
          graph-&gt;listAdj[i] = NULL;
      }
      return true;
  }
  
  void insertEdge(int v1, int v2, Weight weight, TypeGraph *graph) {
      if (v1 &lt; 0 || v1 &gt; graph-&gt;numVertices || v2 &lt; 0 || v2 &gt; graph-&gt;numVertices) {
          return;
      }
      TypePointer actual = graph-&gt;listAdj[v1];
      while (actual-&gt;next) {
          actual = actual-&gt;next;
      }
      TypePointer pNew = (TypePointer) malloc(sizeof(TypeEdge));
      pNew-&gt;vDest = v2;
      pNew-&gt;weight = weight;
      pNew-&gt;next = NULL;
      actual-&gt;next = pNew;
  }
  
  int main() {
      TypeGraph graph;
      bool result = initializeGraph(&amp;graph, 100);
      if (result) {
          insertEdge(2, 3, 1, &amp;graph);
      }
      return 0;
  }
  </code></pre>
  
  <p>The problem is that, instead of initializing the graph with size of one hundred TypePointer, it initializes just size two and do not perform any action. When I try to debug it on <code>Clion</code> it shows this error message: <code>read memory from 0x4000000000000000 failed (0 of 4 bytes read)</code>. If I just run the code it returns code eleven.</p>
  
  <p>Please, can someone help me?</p>