@@ -413,37 +413,44 @@ Error Method::parse_values() {
413
413
return Error::Ok;
414
414
}
415
415
416
+ namespace {
416
417
/* *
417
418
* Private/helper method for populating operator_name from the Operator.
418
419
* operator_name is a char pointer that is already allocated. The size of
419
420
* of this buffer is of size operator_name_size.
420
421
*/
421
- static void populateOperatorName (
422
+ Error populate_operator_name (
422
423
const executorch_flatbuffer::Operator* const & op,
423
424
const size_t operator_name_size,
424
425
char * operator_name) {
425
- int cx;
426
- const bool has_overload = (op->overload ()->size () > 0 );
427
- // Don't append any overload if the overload string is empty.
428
- cx = snprintf (
426
+ const bool has_overload =
427
+ op->overload () != nullptr && op->overload ()->size () > 0 ;
428
+
429
+ ET_CHECK_OR_RETURN_ERROR (
430
+ op->name () != nullptr , InvalidProgram, " Missing operator name" );
431
+ int cx = snprintf (
429
432
operator_name,
430
433
operator_name_size,
431
434
" %s%s%s" ,
432
435
op->name ()->c_str (),
436
+ // Don't append any overload if the overload string is empty.
433
437
has_overload ? " ." : " " ,
434
438
has_overload ? op->overload ()->c_str () : " " );
435
-
436
- ET_CHECK_MSG (cx >= 0 , " String encoding error occured." );
437
- ET_CHECK_MSG (
439
+ ET_CHECK_OR_RETURN_ERROR (cx >= 0 , Internal, " snprintf failed: %d" , cx);
440
+ ET_CHECK_OR_RETURN_ERROR (
438
441
cx < operator_name_size,
439
- " Aborting. Operator name %s%s%s with length %d "
442
+ Internal,
443
+ " Operator name %s%s%s with length %d "
440
444
" truncated to %zu due to internal buffer limit." ,
441
445
op->name ()->c_str (),
442
446
has_overload ? " ." : " " ,
443
447
has_overload ? op->overload ()->c_str () : " " ,
444
448
cx,
445
449
operator_name_size);
450
+
451
+ return Error::Ok;
446
452
}
453
+ } // namespace
447
454
448
455
Error Method::resolve_operator (
449
456
int32_t op_index,
@@ -465,7 +472,10 @@ Error Method::resolve_operator(
465
472
op_index);
466
473
const auto & op = ops->Get (op_index);
467
474
468
- populateOperatorName (op, kTempBufferSizeForName , operator_name);
475
+ Error err = populate_operator_name (op, kTempBufferSizeForName , operator_name);
476
+ if (err != Error::Ok) {
477
+ return err;
478
+ }
469
479
470
480
// resolve tensor meta
471
481
auto method_allocator = memory_manager_->method_allocator ();
@@ -481,7 +491,7 @@ Error Method::resolve_operator(
481
491
exec_aten::DimOrderType* dim_order_ptr = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
482
492
method_allocator, exec_aten::DimOrderType, tensor.dim ());
483
493
size_t size = tensor.dim ();
484
- Error err = get_dim_order (tensor, dim_order_ptr, size);
494
+ err = get_dim_order (tensor, dim_order_ptr, size);
485
495
ET_CHECK_OR_RETURN_ERROR (
486
496
err == Error::Ok,
487
497
InvalidArgument,
0 commit comments