ORT_ENFORCE on the iterator must come before iterator is dereferenced. (#17265)

### Description
Move `ORT_ENFORCE` on the iterator before iterator is used for the first
time.
This commit is contained in:
Dmitri Smirnov 2023-08-23 17:20:01 -07:00 committed by GitHub
parent 6c95d959f3
commit 33c87f6283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,10 +254,11 @@ common::Status SaveInitializedTensors(
auto initialized_tensors_to_allocate = id_to_initialized_tensor;
for (int ort_value_index : initializer_allocation_order) {
const auto entry = initialized_tensors_to_allocate.find(ort_value_index);
ORT_ENFORCE(entry != initialized_tensors_to_allocate.end(),
"OrtValue index: ", ort_value_index, " from initializer_allocation_order not found among initialized tensors");
if (!(utils::HasExternalData(*entry->second) && exec_plan.GetLocation(ort_value_index).Type() == OrtDevice::CPU)) {
// can not trace string tensor
ORT_ENFORCE(entry != initialized_tensors_to_allocate.end() &&
entry->second->data_type() != ONNX_NAMESPACE::TensorProto_DataType_STRING);
ORT_ENFORCE(entry->second->data_type() != ONNX_NAMESPACE::TensorProto_DataType_STRING, "Can not trace string tensor");
ORT_RETURN_IF_ERROR(planner.Trace(entry->first, entry->second));
}
initialized_tensors_to_allocate.erase(entry);