Fixed error in safe buffer checking