Statically analyzed issues. (#2274)
authorNikolay Shchegolev <nikolay.shchegolev@intel.com>
Wed, 16 Sep 2020 15:09:59 +0000 (18:09 +0300)
committerGitHub <noreply@github.com>
Wed, 16 Sep 2020 15:09:59 +0000 (18:09 +0300)
inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp
inference-engine/src/legacy_api/src/net_pass.cpp
inference-engine/src/readers/ir_reader_v7/ie_layer_validators.cpp
inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp
inference-engine/src/transformations/src/transformations/reduce_l1_decomposition.cpp
inference-engine/src/transformations/src/transformations/reduce_l2_decomposition.cpp

index dd27d57..863de89 100644 (file)
@@ -669,6 +669,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
                        [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
         LayerParams attrs = {node->get_friendly_name(), node->description(), details::convertPrecision(node->get_output_element_type(0))};
         auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::ArithmeticReductionKeepDims>(node);
+        if (reduce_node == nullptr)
+            THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of ArithmeticReductionKeepDims.";
         auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
         res->params = params;
         res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False";
@@ -678,6 +680,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
     addSpecificCreator({"ReduceLogicalAnd"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
         LayerParams attrs = {node->get_friendly_name(), "ReduceAnd", details::convertPrecision(node->get_output_element_type(0))};
         auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::LogicalReductionKeepDims>(node);
+        if (reduce_node == nullptr)
+            THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims.";
         auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
         res->params = params;
         res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False";
@@ -687,6 +691,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
     addSpecificCreator({"ReduceLogicalOr"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
         LayerParams attrs = {node->get_friendly_name(), "ReduceOr", details::convertPrecision(node->get_output_element_type(0))};
         auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::LogicalReductionKeepDims>(node);
+        if (reduce_node == nullptr)
+            THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims.";
         auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
         res->params = params;
         res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False";
index 9791218..4dac072 100644 (file)
@@ -398,8 +398,10 @@ bool convertToRNNSeq(CNNLayerPtr cur, const N& net) {
     IE_ASSERT(cell->insData.size() == NS + 1);  // {data, state1, [state2]}
     IE_ASSERT(cell->outData.size() == NS);      // {state1, [state2]}
 
+    auto outData0InputsTo = getInputTo(cell->outData[0]);
     if (getCreatorLayer(cell->insData[0].lock()).lock() != rsp1 ||
-        getInputTo(cell->outData[0]).begin()->second != rsp2)
+            outData0InputsTo.empty() ||
+            outData0InputsTo.begin()->second != rsp2)
         return false;
 
     // Check port mapping
index cae6bd1..7cd900a 100644 (file)
@@ -269,7 +269,7 @@ void CropValidator::checkShapes(const CNNLayer* layer, const vector<SizeVector>&
             }
         } else if (!casted->dim.empty()) {
             int dim = casted->dim[i];
-            if (firstShape[axis] < static_cast<size_t>(offset + dim)) {
+            if (firstShape[axis] < (static_cast<size_t>(offset) + dim)) {
                 THROW_IE_EXCEPTION << "Incorrect crop data! Offset(" << offset << ") + result size of output(" << dim
                                    << ") should be less then input size(" << firstShape[axis] << ") for axis(" << axis
                                    << ")";
index dc2538c..3247875 100644 (file)
@@ -28,6 +28,8 @@ ngraph::pass::FullyConnectedBiasFusion::FullyConnectedBiasFusion() {
 
         if (m_fc == nullptr) {
             m_fc = std::dynamic_pointer_cast<op::FullyConnected>(add_input_1);
+            if (m_fc == nullptr)
+                return false;
             m_bias = add_input_0;
         }
 
index 1390383..87f8fd0 100644 (file)
@@ -20,7 +20,7 @@ ngraph::pass::ReduceL1Decomposition::ReduceL1Decomposition() {
         auto &pattern_to_output = m.get_pattern_value_map();
         auto reduce_l1_node = std::dynamic_pointer_cast<ngraph::opset4::ReduceL1>(pattern_to_output.at(reduce_l1).get_node_shared_ptr());
 
-        if (m_transformation_callback(reduce_l1_node)) {
+        if (reduce_l1_node == nullptr || m_transformation_callback(reduce_l1_node)) {
             return false;
         }
 
index 60e8114..f36cfee 100644 (file)
@@ -20,7 +20,7 @@ ngraph::pass::ReduceL2Decomposition::ReduceL2Decomposition() {
         auto &pattern_to_output = m.get_pattern_value_map();
         auto reduce_l2_node = std::dynamic_pointer_cast<ngraph::opset4::ReduceL2>(pattern_to_output.at(reduce_l2).get_node_shared_ptr());
 
-        if (m_transformation_callback(reduce_l2_node)) {
+        if (reduce_l2_node == nullptr || m_transformation_callback(reduce_l2_node)) {
             return false;
         }