Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by unwind for Segmentation fault in c - probably connected with pointers

The code is rather unsafe. Some issues, not only about the safety but some of these certainly can cause your crash:

  1. Input arguments should be const pointers, for clarity.
  2. The return value of malloc() is not checked, so if the allocation fails you're toast.
  3. Don't cast the return value of malloc() in C.
  4. Don't copy using a loop, use memcpy().
  5. There's no guarantee that j doesn't go out of bounds.
  6. The ret array is never used.

Viewing all articles
Browse latest Browse all 2

Trending Articles