Fix sizeof misuse and variable uninitialization