If it's getting a segmentation fault before that statement (how are you aware of that, are you using gdb??), then the problem it's before executing that assignment.
Assuming you don't know for certain the coredump is being reached before that statement it's certainly difficult to debug as it's a very small amount of code and which is correct. Perhaps the problem isn't there at all, or perhaps a not thought design it's displaying it's lack of error checking at that point.
Whatever be the case, keep in mind that an error of that type it's cause by trying to write locations in memory where you have not access or that don't exist or something like that. It's a memory related issue.