From: 오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 30 Aug 2019 05:49:30 +0000 (+0900) Subject: Fix uncatched exception (#7058) X-Git-Tag: accepted/tizen/unified/20190903.052428~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2af3a2cdcdd94dc567e675634fd6dab9f8ffbfff;p=platform%2Fcore%2Fml%2Fnnfw.git Fix uncatched exception (#7058) Operand::operandSize() can throw exeception because sizeOfDataType() in DataType.h can throw runtime exception Signed-off-by: Hyeongseok Oh --- diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc index 6598c61..3ac73a4 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc @@ -63,12 +63,21 @@ ANeuralNetworksExecution::getOutputOperandIndex(int32_t index) noexcept bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType *type, const neurun::model::OperandIndex index) noexcept { - const auto operand_type = _execution->model().operands.at(index).typeInfo(); - const auto typeInfo = NNAPIConvert::getTypeInfo(type); - - if (operand_type != typeInfo) + try + { + const auto operand_type = _execution->model().operands.at(index).typeInfo(); + const auto typeInfo = NNAPIConvert::getTypeInfo(type); + + if (operand_type != typeInfo) + { + // Data type mismatch + return false; + } + } + catch (const std::exception &e) { - // Data type mismatch + VERBOSE(EXCEPTION) << e.what() << std::endl; + return false; } @@ -99,7 +108,16 @@ bool ANeuralNetworksExecution::haveUnspecifiedDims(const neurun::model::OperandI size_t ANeuralNetworksExecution::getOperandSize(const neurun::model::OperandIndex index) noexcept { - return _execution->model().operands.at(index).operandSize(); + try + { + return _execution->model().operands.at(index).operandSize(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << std::endl; + + return 0; + } } bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOperandType *type, diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc index 268eb0c..e3bb291 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc @@ -214,7 +214,16 @@ bool ANeuralNetworksModel::isExistOperand(uint32_t index) noexcept size_t ANeuralNetworksModel::operandSize(uint32_t index) noexcept { - return _model->operands.at(neurun::model::OperandIndex{index}).operandSize(); + try + { + return _model->operands.at(neurun::model::OperandIndex{index}).operandSize(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << '\n'; + + return 0; + } } bool ANeuralNetworksModel::isUsageSet(uint32_t index) noexcept