Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes inifinte loop in ClassEntry::instance_of() #188

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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