Improve buffer-overflow checking (Bug#8873).