Avoid some shadowing warnings.
Fix a potential null pointer.
Avoid an unlikely buffer overflow.
Fix some sign comparison warnings.
Merge pull request #4045 from unknownbrackets/warnings

Warning fixes