mirror of
https://github.com/vee1e/tflite-micro.git
synced 2026-09-01 17:57:27 +00:00
IF kernel nulltpr fix (#2515)
In some cases if you IF op has 0 outputs, it can reference a nullptr in trying to access node->outputs->size(). This is in the case if your model was flatbuffer_aligned which most likely optimizes away the empty array to nullptr. BUG=[328527454](https://buganizer.corp.google.com/issues/328527454)
This commit is contained in:
parent
79e3f35f3c
commit
15092dfdba
3 changed files with 5 additions and 2 deletions
|
|
@ -67,7 +67,7 @@ TfLiteStatus IfPrepare(TfLiteContext* context, TfLiteNode* node) {
|
|||
// passed to the branch subgraphs. Therefore, the number of subgraph inputs
|
||||
// will be the number of node inputs - 1.
|
||||
size_t num_inputs = node->inputs->size - 1;
|
||||
size_t num_outputs = node->outputs->size;
|
||||
size_t num_outputs = NumOutputs(node);
|
||||
|
||||
MicroGraph& graph_info = micro_context->graph();
|
||||
|
||||
|
|
|
|||
|
|
@ -252,6 +252,7 @@ TfLiteStatus CopySubgraphOutputsToOpOutputs(TfLiteContext* context,
|
|||
TfLiteNode* node,
|
||||
MicroGraph* graph_info,
|
||||
int subgraph_idx) {
|
||||
if (graph_info->NumSubgraphOutputs(subgraph_idx) == 0) return kTfLiteOk;
|
||||
TF_LITE_ENSURE(context, static_cast<size_t>(node->outputs->size) ==
|
||||
graph_info->NumSubgraphOutputs(subgraph_idx));
|
||||
for (int i = 0; i < node->outputs->size; i++) {
|
||||
|
|
|
|||
|
|
@ -259,7 +259,9 @@ TfLiteEvalTensor* MicroInterpreterGraph::GetSubgraphInput(int subgraph_idx,
|
|||
}
|
||||
|
||||
size_t MicroInterpreterGraph::NumSubgraphOutputs(int subgraph_idx) {
|
||||
return model_->subgraphs()->Get(subgraph_idx)->outputs()->size();
|
||||
return model_->subgraphs()->Get(subgraph_idx)->outputs() == nullptr
|
||||
? 0
|
||||
: model_->subgraphs()->Get(subgraph_idx)->outputs()->size();
|
||||
}
|
||||
|
||||
TfLiteEvalTensor* MicroInterpreterGraph::GetSubgraphOutput(int subgraph_idx,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue