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

Possible infinite loop in isChildOf #407

Open
philips77 opened this issue Apr 5, 2022 · 1 comment
Open

Possible infinite loop in isChildOf #407

philips77 opened this issue Apr 5, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@philips77
Copy link
Member

In the isChildOf() method there is a risk of an infinite loop, if the groups point form a cyclic references:

func isChildOf(_ parent: Group) -> Bool {
var group: Group = self
while let p = group.parent {
if p == parent {
return true
}
group = p
}
return false
}

Cyclic groups should be checked on importing and setting a parent.

Note

Nested groups are not used in the sample app and not really well tested. The point of having nested groups is unclear to me, as this only comes in the CDB spec, not in the Mesh Profile. So this is only a way of organizing groups for the user.

@philips77 philips77 added the bug Something isn't working label Apr 5, 2022
@philips77
Copy link
Member Author

The cyclic references should be checked here:

public var parent: Group? {
get {
guard let meshNetwork = meshNetwork else {
return nil
}
if parentAddress == "0000" {
return nil
}
return meshNetwork.groups.first {
$0.groupAddress == parentAddress
}
}
set {
guard let parent = newValue else {
parentAddress = "0000"
return
}
if let meshNetwork = meshNetwork, meshNetwork.groups.contains(parent) {
parentAddress = parent.groupAddress
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant