Re: simple regex for highlighting _/* fails

Rado S <[email protected]>
Newsgroups gmane.network.tin.devel
Message-ID <[email protected]>
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]> -----

> Date: Wed, 11 Apr 2007 09:56:24 +0100 (BST)
> From: Philip Hazel <[email protected]>
> Subject: Re: simple regex for highlighting _/* fails
> 
> On Tue, 10 Apr 2007, Rado S wrote:
> 
> > This is in regex.c (stripped to the relevant parts AFAICS):
> > ------ QUOTE BEGIN ------
> > void highlight_regexes( int row, struct regex_cache *regex, int color)
> > {
> >         char *ptr;
> >         int offsets[6];
> >         int offsets_size = ARRAY_SIZE(offsets);
> >         char buf[LEN];
> > 
> >         /* Get contents of line from the screen */
> >         screen_contents(row, 0, buf);
> >         ptr = buf;
> > 
> >         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.
> 
> -- 
> Philip Hazel, University of Cambridge Computing Service.

----- End forwarded message -----

-- 
© Rado S. -- You must provide YOUR effort for your goal!
EVERY effort counts: at least to show your attitude.
You're responsible for ALL you do: you get what you give.
hilite.patch (text/plain, 512 B)
--- 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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.