 <p>The problem is likely to be at the 2nd <code>cur = cur-&gt;next;</code>, which follows the <code>while</code> loop - at that point the loop has guaranteed that <code>cur == NULL</code>.</p> <p>I'm not sure what you're trying to do in that function (has some code been elided for the example?), so don't really have a suggesting at the moment.</p> <p>Also, as your compiler warnings indicate, nothing is being returned by the function even though it's declared to do so. I would have assumed again that this is because something is removed for the purposes of the example in the question, but then again your compiler is complaining as well. Any caller that uses whatever the function is supposed to return is in for a surprise. That surprise may also be a segfault.</p>