Changeset 383 for trunk/src/zAVLTree.c


Ignore:
Timestamp:
Dec 5, 2011, 10:30:33 PM (10 years ago)
Author:
katerina
Message:

Fix for ticket #281 (warnings from clang static analyzer).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/zAVLTree.c

    r363 r383  
    366366  depthdiff = R_DEPTH(avlnode) - L_DEPTH(avlnode);
    367367
    368   if (depthdiff <= -2) {
     368  if (depthdiff <= -2 && avlnode->left) {
    369369    child = avlnode->left;
    370370
     
    384384    else {
    385385      gchild = child->right;
    386       avlnode->left = gchild->right;
    387       if (avlnode->left != NULL)
    388         avlnode->left->parent = avlnode;
    389       avlnode->depth = CALC_DEPTH(avlnode);
    390       child->right = gchild->left;
    391       if (child->right != NULL)
    392         child->right->parent = child;
    393       child->depth = CALC_DEPTH(child);
    394       gchild->right = avlnode;
    395       if (gchild->right != NULL)
    396         gchild->right->parent = gchild;
    397       gchild->left = child;
    398       if (gchild->left != NULL)
    399         gchild->left->parent = gchild;
    400       gchild->depth = CALC_DEPTH(gchild);
    401       *superparent = gchild;
    402       gchild->parent = origparent;
    403     }
    404   }
    405 
    406   else if (depthdiff >= 2) {
     386      if (gchild)
     387        {
     388          avlnode->left = gchild->right;
     389          if (avlnode->left != NULL)
     390            avlnode->left->parent = avlnode;
     391          avlnode->depth = CALC_DEPTH(avlnode);
     392          child->right = gchild->left;
     393          if (child->right != NULL)
     394            child->right->parent = child;
     395          child->depth = CALC_DEPTH(child);
     396          gchild->right = avlnode;
     397          if (gchild->right != NULL)
     398            gchild->right->parent = gchild;
     399          gchild->left = child;
     400          if (gchild->left != NULL)
     401            gchild->left->parent = gchild;
     402          gchild->depth = CALC_DEPTH(gchild);
     403          *superparent = gchild;
     404          gchild->parent = origparent;
     405        }
     406    }
     407  }
     408
     409  else if (depthdiff >= 2 && avlnode->right) {
    407410    child = avlnode->right;
    408411
     
    422425    else {
    423426      gchild = child->left;
    424       avlnode->right = gchild->left;
    425       if (avlnode->right != NULL)
    426         avlnode->right->parent = avlnode;
    427       avlnode->depth = CALC_DEPTH(avlnode);
    428       child->left = gchild->right;
    429       if (child->left != NULL)
    430         child->left->parent = child;
    431       child->depth = CALC_DEPTH(child);
    432       gchild->left = avlnode;
    433       if (gchild->left != NULL)
    434         gchild->left->parent = gchild;
    435       gchild->right = child;
    436       if (gchild->right != NULL)
    437         gchild->right->parent = gchild;
    438       gchild->depth = CALC_DEPTH(gchild);
    439       *superparent = gchild;
    440       gchild->parent = origparent;
     427      if (gchild)
     428        {
     429          avlnode->right = gchild->left;
     430          if (avlnode->right != NULL)
     431            avlnode->right->parent = avlnode;
     432          avlnode->depth = CALC_DEPTH(avlnode);
     433          child->left = gchild->right;
     434          if (child->left != NULL)
     435            child->left->parent = child;
     436          child->depth = CALC_DEPTH(child);
     437          gchild->left = avlnode;
     438          if (gchild->left != NULL)
     439            gchild->left->parent = gchild;
     440          gchild->right = child;
     441          if (gchild->right != NULL)
     442            gchild->right->parent = gchild;
     443          gchild->depth = CALC_DEPTH(gchild);
     444          *superparent = gchild;
     445          gchild->parent = origparent;
     446        }
    441447    }
    442448  }
Note: See TracChangeset for help on using the changeset viewer.