Remove redundant NULL pointer check.
Fix possible NULL pointer dereferences.
Fix possible buffer overflows.