Fixed a (very improbable) NULL pointer dereferencing bug.
Fixed a couple of undefined behaviour situations due to variables being not initialized and every branches taking negative paths