From 283ae6e5388b15e8bcb05542225f9614946736b1 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 15 Apr 2013 12:27:30 -0700 Subject: [PATCH] Fix some cppcheck warnings in vvp. --- vvp/array.cc | 1 - vvp/symbols.cc | 124 ++++++++++++++++++++++------------------------ vvp/vpi_signal.cc | 1 - vvp/vpip_bin.cc | 3 +- vvp/vpip_hex.cc | 3 +- vvp/vpip_oct.cc | 3 +- 6 files changed, 62 insertions(+), 73 deletions(-) diff --git a/vvp/array.cc b/vvp/array.cc index a798c920d..8a7f1fed9 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -184,7 +184,6 @@ struct __vpiArrayVthrA : public __vpiHandle { case BIT4_Z: /* Return UINT_MAX to indicate an X base. */ return UINT_MAX; - break; case BIT4_1: tval |= 1<leaf_flag); + if (cur->parent) assert(! cur->parent->leaf_flag); - assert(!cur->leaf_flag); - if (cur->parent) assert(! cur->parent->leaf_flag); + while (cur->count == node_width) { + /* Create a new node to hold half the data from cur. */ + struct tree_node_ *new_node = new struct tree_node_; + new_node->leaf_flag = false; + new_node->count = cur->count / 2; + /* cur is not root; new_node becomes sibling. */ + if (cur->parent) new_node->parent = cur->parent; - while (cur->count == node_width) - { - /* Create a new node to hold half the data from cur. */ - new_node = new struct tree_node_; - new_node->leaf_flag = false; - new_node->count = cur->count / 2; - if (cur->parent) - /* cur is not root; new_node becomes sibling. */ - new_node->parent = cur->parent; + /* Move the last half of the data from the end of the old node + * to the beginning of the new node. At the same time, reduce + * the size of the old node. */ + unsigned idx1 = new_node->count; + unsigned idx2 = cur->count; + while (idx1 > 0) { + idx1 -= 1; + idx2 -= 1; + new_node->child[idx1] = cur->child[idx2]; + new_node->child[idx1]->parent = new_node; + cur->count -= 1; + } - /* Move the last half of the data from the end of the old node - to the beginning of the new node. At the same time, reduce - the size of the old node. */ - idx1 = new_node->count; - idx2 = cur->count; - while (idx1 > 0) { - idx1 -= 1; - idx2 -= 1; - new_node->child[idx1] = cur->child[idx2]; - new_node->child[idx1]->parent = new_node; - cur->count -= 1; - } + assert(new_node->count > 0); + assert(cur->count > 0); - assert(new_node->count > 0); - assert(cur->count > 0); + if (cur->parent == 0) { + /* cur is root. Move first half of children to another + * new node, and put the two new nodes in cur. The plan + * here is to make cur into the new root and split its + * contents into 2 children. */ - if (cur->parent == 0) { - /* cur is root. Move first half of children to - another new node, and put the two new nodes - in cur. The plan here is to make cur into - the new root and split its contents into 2 - children. */ + new_node->parent = cur; + struct tree_node_*new2_node = new struct tree_node_; + new2_node->leaf_flag = false; + new2_node->count = cur->count; + new2_node->parent = cur; + for (unsigned idx = 0; idx < cur->count; idx += 1) { + new2_node->child[idx] = cur->child[idx]; + new2_node->child[idx]->parent = new2_node; + } + cur->child[0] = new2_node; + cur->child[1] = new_node; + cur->count = 2; + /* no more ancestors, stop the while loop */ + break; + } - new_node->parent = cur; - struct tree_node_*new2_node = new struct tree_node_; - new2_node->leaf_flag = false; - new2_node->count = cur->count; - new2_node->parent = cur; - for (idx = 0; idx < cur->count; idx += 1) { - new2_node->child[idx] = cur->child[idx]; - new2_node->child[idx]->parent = new2_node; - } - cur->child[0] = new2_node; - cur->child[1] = new_node; - cur->count = 2; - /* no more ancestors, stop the while loop */ - break; - } + /* cur is not root. hook new_node to cur->parent. */ + unsigned idx = 0; + while (cur->parent->child[idx] != cur) { + assert(idx < cur->parent->count); + idx += 1; + } + idx += 1; - /* cur is not root. hook new_node to cur->parent. */ - idx = 0; - while (cur->parent->child[idx] != cur) { - assert(idx < cur->parent->count); - idx += 1; - } + for (unsigned tmp = cur->parent->count ; tmp > idx ; tmp -= 1) { + cur->parent->child[tmp] = cur->parent->child[tmp-1]; + } - idx += 1; + cur->parent->child[idx] = new_node; + cur->parent->count += 1; - for (tmp = cur->parent->count ; tmp > idx ; tmp -= 1) - cur->parent->child[tmp] = cur->parent->child[tmp-1]; - - cur->parent->child[idx] = new_node; - cur->parent->count += 1; - - /* check the ancestor */ - cur = cur->parent; - } + /* check the ancestor */ + cur = cur->parent; + } } /* diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index 86fb6eba5..fc43da193 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -1149,7 +1149,6 @@ static int PV_get_base(struct __vpiPV*rfp) case BIT4_Z: /* We use INT_MIN to indicate an X base. */ return INT_MIN; - break; case BIT4_1: tval |= 1<