Avoid some shadowing warnings.
Fix a potential null pointer.
Avoid an unlikely buffer overflow.
Fix some sign comparison warnings.