Skip to content

Commit

Permalink
fixes inifinte loop in ClassEntry::instance_of (davidcole1340#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1ius authored Nov 16, 2022
1 parent 3b1e2e3 commit 4ea01f8
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/zend/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,19 @@ impl ClassEntry {
///
/// # Parameters
///
/// * `ce` - The inherited class entry to check.
pub fn instance_of(&self, ce: &ClassEntry) -> bool {
if self == ce {
/// * `other` - The inherited class entry to check.
pub fn instance_of(&self, other: &ClassEntry) -> bool {
if self == other {
return true;
}

if ce.flags().contains(ClassFlags::Interface) {
let interfaces = match self.interfaces() {
Some(interfaces) => interfaces,
None => return false,
};

for i in interfaces {
if ce == i {
return true;
}
}
} else {
loop {
let parent = match self.parent() {
Some(parent) => parent,
None => return false,
};

if parent == ce {
return true;
}
}
if other.is_interface() {
return self
.interfaces()
.map_or(false, |mut it| it.any(|ce| ce == other));
}

false
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
}

/// Returns an iterator of all the interfaces that the class implements.
Expand Down

0 comments on commit 4ea01f8

Please sign in to comment.