interpreter_plugin: fix segfault if input/output node not found (#950)
authorVitaliy Cherepanov/AI Tools Lab /SRR/Engineer/삼성전자 <v.cherepanov@samsung.com>
Fri, 10 Aug 2018 09:14:44 +0000 (12:14 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Fri, 10 Aug 2018 09:14:44 +0000 (12:14 +0300)
add intput / output nodes checking

Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
contrib/nnc/libs/backend/interpreter/plugin/src/interpreter_plugin.cpp

index cda86d7..73e8055 100644 (file)
@@ -73,11 +73,22 @@ void *InterpreterPlugin::execute(void *data) {
 
   g->accept(&shapeInference);
 
-  auto input = loadInput(g->getInput(params["input"])->getOperation()->getOutputShape(0));
+  // Check nodes
+  auto inputNode = g->getInput(params["input"]);
+  if (inputNode == nullptr) {
+    throw PluginException("input node <" + params["input"] +"> not found" );
+  }
+
+  auto outputNode = g->getOutput(params["output"]);
+  if (outputNode == nullptr) {
+    throw PluginException("output node <" + params["output"] +"> not found" );
+  }
+
+  auto input = loadInput(inputNode->getOperation()->getOutputShape(0));
   interpreter.setInput(params["input"], input);
   g->accept(&interpreter);
 
-  _out = new TensorVariant(interpreter.getResult(g->getOutput(params["output"]))[0]);
+  _out = new TensorVariant(interpreter.getResult(outputNode)[0]);
   return _out;
 }