[DynInst_API:] Bugs in IBSTree.h?


Date: Sat, 25 Nov 2017 16:52:25 -0600
From: John Mellor-Crummey <johnmc@xxxxxxxx>
Subject: [DynInst_API:] Bugs in IBSTree.h?
The code below comes from IBSTree.h in master (https://github.com/dyninst/dyninst/blob/master/common/h/IBSTree.h), though it is similar in the new-parallel-parsing branch. 

I donât see how it could be right. When an IBSTree is non-empty, root is non-null. 

Problem 1: This code would blow up with an empty root as it would try to dereference root in the test for the while loop.

Problem 2: As I read it, the test for the while loops are not affected by the assignments in their loop bodies. How is the first while not an infinite loop if right->left is non-NULL? Similarly, how is the second while not an infinite loop if root->right is non-NULL.

const_iterator begin() const {
       iterator b = root;
       while(root->left) b = root->left;
       return b;
}
const_iterator end() const {
       iterator e = root;
       while(root->right) e = root->right;
       return e;
}

Shouldnât the code read:

const_iterator begin() const {
       iterator b = root;
       while(b->left) b = root->left;
       return b;
}
const_iterator end() const {
       iterator e = root;
       while(e->right) e = root->right;
       return e;
}

--
John Mellor-Crummey Professor
Dept of Computer Science Rice University
email: johnmc@xxxxxxxx phone: 713-348-5179

[← Prev in Thread] Current Thread [Next in Thread→]