Fixes to various non-obvious bugs

I played around with a static analysis tool and found some issues.
Oh no, it's ok. I've read toCString(..)