Avoid a possible NULL dereference (found by Coverity), also avoid some