Add overflow check to factorial.