[geany/geany] 83e7af: Fix return value of search_find_text() when the match is out of bounds

Colomban Wendling git-noreply at geany.org
Mon Dec 10 21:45:34 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 10 Dec 2012 21:45:34 UTC
Commit:      83e7afc1991c882890d6e28027e0ec26552c0944
             https://github.com/geany/geany/commit/83e7afc1991c882890d6e28027e0ec26552c0944

Log Message:
-----------
Fix return value of search_find_text() when the match is out of bounds

When performing a regular expression search on a range, and there is a
match past the end of the range, search_find_text() used to improperly
return the position of the match, but without filling the
Sci_TextToFind structure.  This lead to the calling code assume there
was a match, and maybe read the uninitialized fields in the
Sci_TextToFind structure, thus leading to undefined behavior.

So, fix search_find_text() so it properly returns -1 when there is a
match but it is outside the bounds.


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

Modified: src/search.c
4 files changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -1989,7 +1989,9 @@ gint search_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *t
 	pos = ttf->chrg.cpMin;
 	ret = find_regex(sci, pos, regex);
 
-	if (ret >= 0 && ret < ttf->chrg.cpMax)
+	if (ret >= ttf->chrg.cpMax)
+		ret = -1;
+	else if (ret >= 0)
 	{
 		ttf->chrgText.cpMin = regex_matches[0].start;
 		ttf->chrgText.cpMax = regex_matches[0].end;



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


More information about the Commits mailing list