瀏覽代碼

fix: remove an unchecked results coverity warning; simplify isNodeInTree

Julius Pfrommer 8 年之前
父節點
當前提交
9184288603

+ 2 - 2
src/server/ua_server_internal.h

@@ -135,10 +135,10 @@ UA_StatusCode
 getTypeHierarchy(UA_NodeStore *ns, const UA_Node *rootRef, UA_Boolean inverse,
                  UA_NodeId **typeHierarchy, size_t *typeHierarchySize);
 
-UA_StatusCode
+UA_Boolean
 isNodeInTree(UA_NodeStore *ns, const UA_NodeId *rootNode,
              const UA_NodeId *nodeToFind, const UA_NodeId *referenceTypeIds,
-             size_t referenceTypeIdsSize, UA_Boolean *found);
+             size_t referenceTypeIdsSize);
 
 const UA_Node *
 getNodeType(UA_Server *server, const UA_Node *node);

+ 10 - 19
src/server/ua_server_utils.c

@@ -156,18 +156,15 @@ getTypeHierarchy(UA_NodeStore *ns, const UA_Node *rootRef, UA_Boolean inverse,
 }
 
 /* Recursively searches "upwards" in the tree following specific reference types */
-UA_StatusCode
+UA_Boolean
 isNodeInTree(UA_NodeStore *ns, const UA_NodeId *leafNode, const UA_NodeId *nodeToFind,
-             const UA_NodeId *referenceTypeIds, size_t referenceTypeIdsSize, UA_Boolean *found) {
-    UA_StatusCode retval = UA_STATUSCODE_GOOD;
-    if(UA_NodeId_equal(leafNode, nodeToFind)) {
-        *found = true;
-        return UA_STATUSCODE_GOOD;
-    }
+             const UA_NodeId *referenceTypeIds, size_t referenceTypeIdsSize) {
+    if(UA_NodeId_equal(leafNode, nodeToFind))
+        return true;
 
     const UA_Node *node = UA_NodeStore_get(ns,leafNode);
     if(!node)
-        return UA_STATUSCODE_BADINTERNALERROR;
+        return false;
 
     /* Search upwards in the tree */
     for(size_t i = 0; i < node->referencesSize; i++) {
@@ -176,19 +173,13 @@ isNodeInTree(UA_NodeStore *ns, const UA_NodeId *leafNode, const UA_NodeId *nodeT
 
         /* Recurse only for valid reference types */
         for(size_t j = 0; j < referenceTypeIdsSize; j++) {
-            if(!UA_NodeId_equal(&node->references[i].referenceTypeId, &referenceTypeIds[j]))
-                continue;
-            retval = isNodeInTree(ns, &node->references[i].targetId.nodeId, nodeToFind,
-                                  referenceTypeIds, referenceTypeIdsSize, found);
-            if(*found || retval != UA_STATUSCODE_GOOD)
-                return retval;
-            break;
+            if(UA_NodeId_equal(&node->references[i].referenceTypeId, &referenceTypeIds[j]) &&
+               isNodeInTree(ns, &node->references[i].targetId.nodeId, nodeToFind,
+                            referenceTypeIds, referenceTypeIdsSize))
+                return true;
         }
     }
-
-    /* Dead end */
-    *found = false;
-    return UA_STATUSCODE_GOOD;
+    return false;
 }
 
 const UA_Node *

+ 5 - 10
src/server/ua_services_attribute.c

@@ -505,12 +505,8 @@ UA_Variant_matchVariableDefinition(UA_Server *server, const UA_NodeId *variableD
     if(!UA_NodeId_equal(valueDataTypeId, variableDataTypeId)) {
         /* is this a subtype? */
         const UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
-        UA_Boolean found = false;
-        UA_StatusCode retval = isNodeInTree(server->nodestore, valueDataTypeId,
-                                            variableDataTypeId, &subtypeId, 1, &found);
-        if(retval != UA_STATUSCODE_GOOD)
-            return retval;
-        if(found)
+        if(isNodeInTree(server->nodestore, valueDataTypeId,
+                        variableDataTypeId, &subtypeId, 1))
             goto check_array;
 
         const UA_DataType *variableDataType = findDataType(variableDataTypeId);
@@ -595,13 +591,12 @@ UA_VariableNode_setDataType(UA_Server *server, UA_VariableNode *node,
 
     /* Does the new type match the constraints of the variabletype? */
     UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
-    UA_Boolean found = false;
-    UA_StatusCode retval = isNodeInTree(server->nodestore, dataType,
-                                        &vt->dataType, &subtypeId, 1, &found);
-    if(retval != UA_STATUSCODE_GOOD || !found)
+    if(!isNodeInTree(server->nodestore, dataType,
+                     &vt->dataType, &subtypeId, 1))
         return UA_STATUSCODE_BADTYPEMISMATCH;
 
     /* Check if the current value would match the new type */
+    UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(node->value.data.value.hasValue) {
         retval = UA_Variant_matchVariableDefinition(server, dataType, node->valueRank,
                                                     node->arrayDimensionsSize,

+ 2 - 3
src/server/ua_services_call.c

@@ -92,9 +92,8 @@ Service_Call_single(UA_Server *server, UA_Session *session,
     for(size_t i = 0; i < methodCalled->referencesSize; i++) {
         if(methodCalled->references[i].isInverse &&
            UA_NodeId_equal(&methodCalled->references[i].targetId.nodeId, &withObject->nodeId)) {
-            //TODO adjust maxDepth to needed tree depth (define a variable in config?)
-            isNodeInTree(server->nodestore, &methodCalled->references[i].referenceTypeId,
-                         &hasComponentNodeId, &hasSubTypeNodeId, 1, &found);
+            found = isNodeInTree(server->nodestore, &methodCalled->references[i].referenceTypeId,
+                                 &hasComponentNodeId, &hasSubTypeNodeId, 1);
             if(found)
                 break;
         }

+ 2 - 4
src/server/ua_services_nodemanagement.c

@@ -379,10 +379,8 @@ checkParentReference(UA_Server *server, UA_Session *session, UA_NodeClass nodeCl
     /* Test if the referencetype is hierarchical */
     const UA_NodeId hierarchicalReference =
         UA_NODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES);
-    UA_Boolean found = false;
-    UA_StatusCode retval = isNodeInTree(server->nodestore, referenceTypeId,
-                                        &hierarchicalReference, &subtypeId, 1, &found);
-    if(retval != UA_STATUSCODE_GOOD || !found) {
+    if(!isNodeInTree(server->nodestore, referenceTypeId,
+                     &hierarchicalReference, &subtypeId, 1)) {
         UA_LOG_DEBUG_SESSION(server->config.logger, session,
                              "AddNodes: Reference type is not hierarchical");
         return UA_STATUSCODE_BADREFERENCETYPEIDINVALID;