Add buffer overflow check