Add NULL check before dereferencing a pointer.

Found by Goanna.
Mark a variable as unused rather than casting before initialisation.

Found by Goanna.