Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Cleanup and sanity-checking of use of strncpy/strcpy (Coverity static analysis)
[palacios.git] / palacios / src / palacios / vmm_multitree.c
index 5c9adb7..6b9e659 100644 (file)
@@ -57,25 +57,39 @@ struct v3_mtree * v3_mtree_create_node(struct v3_mtree * root, char * name) {
     struct v3_mtree * ret = NULL;
 
 
+    PrintDebug(VM_NONE, VCORE_NONE, "Creating Node %s\n", name);
+
+
+    if (!node) {
+       PrintError(VM_NONE, VCORE_NONE, "Cannot allocate multitree node\n");
+       return NULL;
+    }
+
     memset(node, 0, sizeof(struct v3_mtree));
-    strncpy(node->name, name, 50);
+    strncpy(node->name, name, V3_MTREE_NAME_LEN);
+    node->name[V3_MTREE_NAME_LEN-1] = 0;
 
     if ((ret = __insert_mtree_node(root, node))) {
+       PrintError(VM_NONE, VCORE_NONE, "Insertion failure\n");
        V3_Free(node);
        return NULL;
     }
 
+    PrintDebug(VM_NONE, VCORE_NONE, "Node (%s)=%p, root=%p, root->child=%p\n", node->name, node, root, root->child.rb_node);
 
     v3_rb_insert_color(&(node->tree_node), &(root->child));
 
+    PrintDebug(VM_NONE, VCORE_NONE, "balanced\n");
+
     return node;
 }
 
 
 struct v3_mtree * v3_mtree_create_subtree(struct v3_mtree * root, char * name) {
-    struct v3_mtree * node = v3_mtree_create_node(root, name);
+    struct v3_mtree * node = NULL;
 
-    PrintDebug("Creating Subtree %s\n", name);
+    PrintDebug(VM_NONE, VCORE_NONE, "Creating Subtree %s\n", name);
+    node = v3_mtree_create_node(root, name);
 
     if (node == NULL) {
        return NULL;
@@ -89,10 +103,10 @@ struct v3_mtree * v3_mtree_create_subtree(struct v3_mtree * root, char * name) {
 
 struct v3_mtree * v3_mtree_create_value(struct v3_mtree * root, char * name, 
                                        uint64_t size, void * value) {
-    struct v3_mtree * node = v3_mtree_create_node(root, name);
-
-    PrintDebug("Creating value %s\n", name);
+    struct v3_mtree * node  = NULL;
 
+    PrintDebug(VM_NONE, VCORE_NONE, "Creating value %s\n", name);    
+    node = v3_mtree_create_node(root, name);
 
     if (node == NULL) {
        return NULL;
@@ -111,7 +125,7 @@ struct v3_mtree * v3_mtree_find_node(struct v3_mtree * root, char * name) {
     struct v3_mtree * tmp_node = NULL;
 
     if (root->subtree == 0) {
-       PrintError("Searching for node on a non-root mtree (search=%s), root=%s\n", name, root->name);
+       PrintError(VM_NONE, VCORE_NONE, "Searching for node on a non-root mtree (search=%s), root=%s\n", name, root->name);
        return NULL;
     }
    
@@ -153,3 +167,24 @@ struct v3_mtree * v3_mtree_find_value(struct v3_mtree * root, char * name) {
 
     return node;
 }
+
+
+struct v3_mtree * v3_mtree_first_child(struct v3_mtree * root) {
+    struct rb_node * node = v3_rb_first(&(root->child));
+
+    if (node == NULL) {
+       return NULL;
+    }
+
+    return rb_entry(node, struct v3_mtree, tree_node);
+}
+
+
+struct v3_mtree * v3_mtree_next_node(struct v3_mtree * node) {
+    struct rb_node * next_node = v3_rb_next(&(node->tree_node));
+
+    if (next_node == NULL) {
+       return NULL;
+    }
+    return rb_entry(next_node, struct v3_mtree, tree_node);
+}