title: Segfault Cannot access memory at address
body: <p>I got a segmentation fault on the code section below: (regarding this segfault , I am asking 2 question in one topic)</p>
  
  <pre><code>req_cw(ECM_REQUEST *er, int32_t flag, int32_t reader_types){
  
      LL_NODE *ptr;
      for (ptr = er-&gt;matching_rdr-&gt;initial ; ptr ; ptr = ptr-&gt;nxt) {
          if (ptr == er-&gt;fail)
              break;
      rdr = (struct s_reader*)ptr-&gt;obj;
      we_equest(rdr-&gt;fd, er);
      }
  }
  </code></pre>
  
  <p>As you see, even with the control structure with <code>if(ptr-&gt;obj &amp;&amp; ptr)</code> to be sure <code>ptr</code> (or <code>ptr-&gt;obj</code> won't be <code>null</code> pointer) but it doesn't prevent it and after segmentation fault when I tried to print the value <code>ptr-&gt;obj</code> with:</p>
  
  <p>print ptr->obj  , gdb says :</p>
  
  <blockquote>
    <p>(gdb) print ptr $1 = (LL_NODE *) 0x149 </p>
    
    <p>(gdb) x 0x149 </p>
    
    <p>0x149: Cannot access memory at address 0x149</p>
  </blockquote>
  
  <p>My question is: How can I prevent this segmentation fault , why this segmentation fault happens and how would I fix it?</p>
  
  <ol>
  <li>Regarding this segfault , when with gdb , i had checked frame 1 (one frame before when segfault happened) , i figured out that</li>
  </ol>
  
  <p>er->cw is <code>"\000 &lt;repeats 15 times&gt;"</code>
  my question is how could I control if <code>er-&gt;cw</code> won't be equal of <code>"'\000' &lt;repeats 15 times"</code>?</p>
  
  <p>I did this, I know it's not correct (and I missed something) , that's why I ask here</p>
  
  <pre><code>if (er-&gt;cw)
  req_cw(er , ...)
  </code></pre>
  
  <p>The problem is  with adding <code>if(er-&gt;cw)</code>. I think <code>cw</code> is character and I shouldn't behave like integer , but I don't know how to check it to not be zero?, I mean , even with this line again when I check with gdb , still <code>er-&gt;cw</code> with value of "'\000' " is passing , so how with if control block I could check when <code>er-&gt;cw</code> is not equal to '\000' " ?</p>
  
  <p>Thanks in advance.</p>