Fix pointers casting

C-style pointer casting doesn't perform runtime check so it's not safe.