[geany/geany] a09123: Fix searching out of document range

Colomban Wendling git-noreply at xxxxx
Fri Jul 27 22:32:26 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Fri, 27 Jul 2012 22:32:26
Commit:      a091238617a5461a2f5642e9589f15748f4e28ac
             https://github.com/geany/geany/commit/a091238617a5461a2f5642e9589f15748f4e28ac

Log Message:
-----------
Fix searching out of document range

If a search matched the very last character of the document, next
search attempt started out of the document bounds.  This even lead
to an infinite loop due to an improper sanity check.

By the way, this fixes matching of contiguous results, as the next
search used to improperly skip one character after the result.
Although this looks like a huge issue, it was actually visible almost
only on the match count since the whole matching line was printed.


Modified Paths:
--------------
    src/search.c

Modified: src/search.c
7 files changed, 3 insertions(+), 4 deletions(-)
===================================================================
@@ -1894,7 +1894,7 @@ static gint find_regex(ScintillaObject *sci, guint pos, GRegex *regex)
 	GMatchInfo *minfo;
 	gint ret = -1;
 
-	g_return_val_if_fail(pos <= (guint)sci_get_length(sci), FALSE);
+	g_return_val_if_fail(pos <= (guint)sci_get_length(sci), -1);
 
 	/* clear old match */
 	SETPTR(regex_match_text, NULL);
@@ -2035,7 +2035,7 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, gi
 	ttf.lpstrText = (gchar *)search_text;
 	while (1)
 	{
-		gint pos, line, start, find_len;
+		gint pos, line, find_len;
 
 		pos = search_find_text(doc->editor->sci, flags, &ttf);
 		if (pos == -1)
@@ -2055,8 +2055,7 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, gi
 			prev_line = line;
 		}
 
-		start = ttf.chrgText.cpMax + 1;
-		ttf.chrg.cpMin = start;
+		ttf.chrg.cpMin = ttf.chrgText.cpMax;
 	}
 	g_free(short_file_name);
 	return count;


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Commits mailing list