Fix ASan error while accessing opcode->custom_name.

PiperOrigin-RevId: 251879003
This commit is contained in:
Sachin Joglekar 2019-06-06 10:35:30 -07:00 committed by TensorFlower Gardener
parent a372bb0e9d
commit dada3c3688

View File

@ -68,7 +68,7 @@ std::unique_ptr<Allocation> GetAllocationFromFile(const char* filename,
bool use_nnapi) { bool use_nnapi) {
std::unique_ptr<Allocation> allocation; std::unique_ptr<Allocation> allocation;
if (mmap_file && MMAPAllocation::IsSupported()) { if (mmap_file && MMAPAllocation::IsSupported()) {
allocation.reset(new MMAPAllocation(filename, error_reporter)); allocation.reset(new MMAPAllocation(filename, error_reporter));
} else { } else {
allocation.reset(new FileCopyAllocation(filename, error_reporter)); allocation.reset(new FileCopyAllocation(filename, error_reporter));
} }
@ -228,17 +228,23 @@ TfLiteStatus InterpreterBuilder::BuildLocalIndexToRegistrationMapping() {
} }
// If it's an unresolved custom op, allow it for now. It might be resolved // If it's an unresolved custom op, allow it for now. It might be resolved
// by a delegate later. // by a delegate later.
if (!opcode->custom_code()) {
error_reporter_->Report(
"Operator with CUSTOM builtin_code has no custom_code.\n");
return status;
}
const auto* op_name = opcode->custom_code()->c_str();
TfLiteRegistration unresolved_op{nullptr, TfLiteRegistration unresolved_op{nullptr,
nullptr, nullptr,
nullptr, nullptr,
/*invoke*/ &UnresolvedOpInvoke, /*invoke*/ &UnresolvedOpInvoke,
nullptr, nullptr,
BuiltinOperator_CUSTOM, BuiltinOperator_CUSTOM,
opcode->custom_code()->c_str(), op_name,
1}; 1};
unresolved_custom_ops_.push_back(unresolved_op); unresolved_custom_ops_.push_back(unresolved_op);
registration = &unresolved_custom_ops_.back(); registration = &unresolved_custom_ops_.back();
has_flex_op_ |= IsFlexOp(registration->custom_name); has_flex_op_ |= IsFlexOp(op_name);
status = kTfLiteOk; status = kTfLiteOk;
} }
flatbuffer_op_index_to_registration_.push_back(registration); flatbuffer_op_index_to_registration_.push_back(registration);