typo
add safety checks against buffer boundaries

fixes #7