Overview
| Artifact ID: | 4afb2980e019ddd1518c21f44e5a192023b7ffb8 |
|---|---|
| Ticket: | d7ea9f9853e8438db20f38c27bd657ecb2d48438
makesearch() can create a useless state |
| User & Date: | tgl on 2015-09-09 22:39:26 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
I noticed that makesearch() contains a minor bug that often causes it to clone a successor of the "pre" state twice not once. AFAICT the extra state is unreachable and thus there is no visible effect, but it's still a waste of resources. The problem occurs when the first state seen by the "make a list of the states" search is seen twice because there are two arcs from the "pre" state to the same state. The first time, we do s->tmp = slist; slist = s; but since slist was previously NULL, s->tmp doesn't change. The second time, the test for s->tmp == NULL mistakenly thinks we hadn't visited this state, so it does that again. Now we have slist pointing to a state whose tmp field also points to itself, so we'll visit it twice in the "do the splits" loop. The second visit makes a second clone of this state, but since we already freed all the state's inarcs from places other than pre, the second clone receives no inarcs and is useless. The problem can be seen to exist by adding a dumpnfa() call after the call to makesearch(). On a test case like regexp {b*b} {a}, this printout results: final cleanup: pre 1, post 0, bos [2], bol [3], eos [4], eol [5] 0@ no out arcs 1> [0]->3 [1]->3 [2]->3 [3]->3 2. [0]->0 [1]->0 [4]->0 [5]->0 3. [1]->3 [1]->2 max 5 # 1( 1): b # 2(ps): # 3(ps): # 4(ps): # 5(ps): after makesearch: pre 1, post 0, bos [2], bol [3], eos [4], eol [5] 0@ no out arcs 1> [0]->3 [1]->3 [2]->3 [3]->3 [0]->1 [1]->1 [2]->1 [3]->1 2. [0]->0 [1]->0 [4]->0 [5]->0 3. [1]->2 [1]->4 4. [1]->2 [1]->4 5. [1]->4 [1]->2 max 5 # 1( 1): b # 2(ps): # 3(ps): # 4(ps): # 5(ps): Notice the lack of ways to reach state 5. I think the fix is simple: the test if (b != NULL && s->tmp == NULL) needs to be if (b != NULL && s->tmp == NULL && s != slist) - foundin changed to: "8.6.4"
- is_private changed to: "0"
- login: "tgl"
- priority changed to: "5 Medium"
- private_contact changed to: "26864b65f1c6ce8bda86f87ed9c554e19ac0390d"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "tgl"
- subsystem changed to: "43. Regexp"
- title changed to: "makesearch() can create a useless state"
- type changed to: "Bug"