Fix buffer overflow stuff for Python 3

Fix test failures on Python 3 and make PEP-8 compliant.

Thanks for your changes!