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

Empty concat causes vector error #26

Closed
jbclements opened this issue Jun 23, 2021 · 5 comments
Closed

Empty concat causes vector error #26

jbclements opened this issue Jun 23, 2021 · 5 comments

Comments

@jbclements
Copy link

Using an empty concatenation as part of an SRE pattern can cause an out-of-range vector reference.

(irregex-search '(or (:) "was") "abc")

pajaro2:/tmp/irregex (git)-[master]- clements> scheme
Chez Scheme Version 9.5.4
Copyright 1984-2020 Cisco Systems, Inc.

> (import (irregex))
> (irregex-search '(or (:) "was") "abc")
Exception in vector-ref: 3 is not a valid index for #(0 0)
Type (debug) to enter the debugger.
>
@ashinn
Copy link
Owner

ashinn commented Jun 28, 2021

Wow... how did you even find this example? :)

We can rewrite these cases to (? (or "was")) but I want to figure out why this confuses the number of states.

@jbclements
Copy link
Author

Well, as you can imagine, I was using Z3 to construct a full proof of correctness of the code...

Uh, no. It was basically just stupidity and/or luck. I think I wasn't yet sure how to specify an empty match.

With that said, I suppose a simple tester that enumerates all small SREs might well have found it. XSmith, maybe? Dunno.

@sjamaan
Copy link
Collaborator

sjamaan commented Jul 5, 2021

It looks like somehow the states corresponding to the second or argument get entirely dropped:

> (sre->nfa '(or (:) "was") 0)
#(0 -1 () () () ((3 . #f) (0 . #f)) () ())

@sjamaan
Copy link
Collaborator

sjamaan commented Jul 5, 2021

OK, turned out to be a pretty simple fix

@sjamaan
Copy link
Collaborator

sjamaan commented Jul 5, 2021

Could you review it @ashinn, just to make sure it is indeed the correct fix?

@ashinn ashinn closed this as completed in b311676 Jul 5, 2021
ashinn added a commit that referenced this issue Jul 5, 2021
…nces-in-or

Fix #26 by taking the max of the inserted state numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants