Article View: net.bugs
Article #206fgrep
From: Geoff Whale
Date: Wed, 23 May 1984 20:23
Date: Wed, 23 May 1984 20:23
44 lines
2115 bytes
2115 bytes
The following bug can be found in many releases, notably Level 7
and system V (fgrep version 1.2).
Try matching the patterns "roar" and "arrow"
against the subject "arroar".
It will fail to match due to a problem in setting
fail links in cfail() - this was probably never noticed because
of the highly obscure and unstructured nature of the implementation,
which looks more like Fortran than C.
The expedient fix (and the poor quality of the original code)
is evident from the diff listing below:
317c317
< *rear++ = s->nst;
---
> *rear++ = s;
339,346c339,351
< floop: if (state == 0) state = w;
< if (state->inp == c) {
< qloop: q->fail = state->nst;
< if ((state->nst)->out == 1) q->out = 1;
< if ((q = q->link) != 0) goto qloop;
< }
< else if ((state = state->link) != 0)
< goto floop;
---
> while (state != NULL && state->inp != c)
> if (state->link != NULL)
> state = state->link;
> else /* no more alternatives at this level */
> state = state->fail;
> if (state == NULL)
> state = w; /* first level node */
> else
> state = state->nst; /* success link */
> do {
> q->fail = state;
> q->out |= state->out;
> } while ((q = q->link) != NULL);
The program has been completely rewritten at UNSW to use malloc()
to obtain tree nodes when needed (the original version declares
an incredible 96076 bytes of data!), to avoid useless leaf
nodes in the tree, and to accept the other grep options -s and -y.
-- Geoff Whale (geoffw:elecvax)
Technical Details
Message-ID:
<194@elecvax.SUN>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!harpo!decvax!mulga!munnari!basser!elecvax!geoffwShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B UNSW 1.0 3/14/84; site elecvax.SUN Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!harpo!decvax!mulga!munnari!basser!elecvax!geoffw From: geoffw@elecvax.SUN (Geoff Whale) Newsgroups: net.bugs,net.bugs.usg,net.bugs.v7 Subject: fgrep Message-ID: <194@elecvax.SUN> Date: Wed, 23-May-84 16:23:36 EDT Article-I.D.: elecvax.194 Posted: Wed May 23 16:23:36 1984 Date-Received: Sat, 26-May-84 12:22:47 EDT Organization: EE and CS, Uni of NSW, Sydney, Australia Lines: 44