Re: simple regex for highlighting _/* fails
Urs Janßen <[email protected]>
| Newsgroups | gmane.network.tin.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Apr 11, 2007 at 03:04:24PM +0200, Rado S wrote: > Moin moin, > > the PCRE author spotted the error quicky, and I verified the patch > works, for details see http://www.pcre.org/pcre.txt, middle of section > "How pcre_exec() returns captured substrings", patch attached: > > ----- Forwarded message from Philip Hazel <[email protected]> ----- > > > int offsets[6]; > > > int offsets_size = ARRAY_SIZE(offsets); > > > > > > while (pcre_exec(regex->re, regex->extra, ptr, strlen(ptr), 0, 0, offsets, offsets_size) > 0) { > > > > Instead of >0, that should be >= 0 because a value of 0 is returned if > > there is a match but not enough room in the offsets to store all the > > capturing parentheses. That's the bug. An offsets vector that is only 6 > > long has room for just the main match plus one set of capturing parens. > ----- End forwarded message ----- > > --- torg/src/regex.c Tue Mar 27 20:25:48 2007 > +++ tgo/src/regex.c Wed Apr 11 14:40:36 2007 > @@ -162,7 +162,7 @@ > #endif /* USE_CURSES */ > ptr = buf; > > - while (pcre_exec(regex->re, regex->extra, ptr, strlen(ptr), 0, 0, offsets, offsets_size) > 0) { > + while (pcre_exec(regex->re, regex->extra, ptr, strlen(ptr), 0, 0, offsets, offsets_size) >= 0) { > /* we have a match */ > if (color >= 0) /* color the matching text */ > word_highlight_string(row, (ptr - buf) + offsets[0], offsets[1] - offsets[0], color); thanks, fixed (also twice in misc.c:eat_re()) - I didn't bother mallocing a big enough offsets[] as we are not interrested in the subpatterns. urs -- "Only whimps use tape backup: _real_ men just upload their important stuff on ftp, and let the rest of the world mirror it ;)" - Linus