cfallin / boolean_expression

A Rust library for manipulating and evaluating Boolean expressions and BDDs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic when persisting an empty BDD

Ravenslofty opened this issue · comments

commented

So, while experimenting with boolean_expression, I found that calling PersistedBDD::persist() on an empty BDD panics.

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/lofty/.cargo/registry/src/github.com-1ecc6299db9ec823/boolean_expression-0.4.3/src/bdd.rs:629:25

Should the <= in

        while self.next_output_func <= f {

be < instead?

@Ravenslofty thanks for the report!

As the BDD is empty, I imagine the f parameter was BDD_ZERO or BDD_ONE in this case?

The <= is correct (we want to persist f itself) but the zero/one terminals are usize::MAX - 1 and usize::MAX, so the loop will most definitely run off the end of the nodes array. The correct behavior is just to return early if trying to persist a constant zero/one (there are no nodes needed to describe the function, just the index).

Let me know if this commit addresses your issue or not! I'll cut a new release if so.

commented

Yep, it does; thank you!

Great! I just published 0.4.4 to crates.io with this fix. Thanks again for the report.