Core/Misc: Fix some static analysis issues

Add some asserts and additional NULL checks as sanity checks.