SF.net SVN: geany: [1261] branches/geany-0.10.1

ntrel at users.sourceforge.net ntrel at xxxxx
Thu Feb 8 13:12:49 UTC 2007


Revision: 1261
          http://svn.sourceforge.net/geany/?rev=1261&view=rev
Author:   ntrel
Date:     2007-02-08 05:12:48 -0800 (Thu, 08 Feb 2007)

Log Message:
-----------
Set single undo action when toggling multiple lines. (r1173)
Prevent some possible invalid memory reads. (r1171)

Modified Paths:
--------------
    branches/geany-0.10.1/NEWS
    branches/geany-0.10.1/src/sci_cb.c
    branches/geany-0.10.1/src/sciwrappers.c
    branches/geany-0.10.1/src/utils.c

Modified: branches/geany-0.10.1/NEWS
===================================================================
--- branches/geany-0.10.1/NEWS	2007-02-08 13:08:15 UTC (rev 1260)
+++ branches/geany-0.10.1/NEWS	2007-02-08 13:12:48 UTC (rev 1261)
@@ -7,6 +7,8 @@
 	  loaded first.
 	* Fixed autocompletion missing tag matches.
 	* Fixed a wrong PASCAL autocompletion.
+	* Set single undo action when toggling multiple lines.
+	* Prevent some possible invalid memory reads.
 
     Internationalisation:
     * New translations: fi (thanks to Harri Koskinen).

Modified: branches/geany-0.10.1/src/sci_cb.c
===================================================================
--- branches/geany-0.10.1/src/sci_cb.c	2007-02-08 13:08:15 UTC (rev 1260)
+++ branches/geany-0.10.1/src/sci_cb.c	2007-02-08 13:12:48 UTC (rev 1261)
@@ -258,7 +258,7 @@
 			{
 				gint start, pos = SSM(sci, SCI_GETCURRENTPOS, 0, 0);
 				start = pos;
-				while (sci_get_char_at(sci, --start) != '&') ;
+				while (start > 0 && sci_get_char_at(sci, --start) != '&') ;
 
 				SSM(sci, SCI_INSERTTEXT, pos - 1, (sptr_t) nt->text);
 			}
@@ -830,7 +830,7 @@
 	sci_get_text_range(sci, pos - 16, pos - 1, buf);
 	// check the first 8 characters of buf for whitespace, but only in this line
 	i = 14;
-	while (isalpha(buf[i])) i--;	// find pos before keyword
+	while (i >= 0 && isalpha(buf[i])) i--;	// find pos before keyword
 	while (i >= 0 && buf[i] != '\n' && buf[i] != '\r') // we want to stay in this line('\n' check)
 	{
 		if (! isspace(buf[i]))
@@ -1110,7 +1110,7 @@
 		x = strlen(indent);
 		// find the start of the <table tag
 		i = 1;
-		while (sci_get_char_at(sci, pos - i) != '<') i++;
+		while (i <= pos && sci_get_char_at(sci, pos - i) != '<') i++;
 		// add all non whitespace before the tag to the indent string
 		while ((pos - i) != indent_pos)
 		{
@@ -1234,12 +1234,17 @@
 
 	for (i = first_line; (i <= last_line) && (! break_loop); i++)
 	{
+		gint buf_len;
+
 		line_start = sci_get_position_from_line(doc_list[idx].sci, i);
 		line_len = sci_get_line_length(doc_list[idx].sci, i);
 		x = 0;
 
-		sci_get_text_range(doc_list[idx].sci, line_start, MIN((line_start + 255), (line_start + line_len - 1)), sel);
-		sel[MIN(255, (line_len - 1))] = '\0';
+		buf_len = MIN((gint)sizeof(sel) - 1, line_len - 1);
+		if (buf_len <= 0)
+			continue;
+		sci_get_text_range(doc_list[idx].sci, line_start, line_start + buf_len, sel);
+		sel[buf_len] = '\0';
 
 		while (isspace(sel[x])) x++;
 
@@ -1361,14 +1366,21 @@
 	co_len = strlen(co);
 	if (co_len == 0) return;
 
+	SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0);
+
 	for (i = first_line; (i <= last_line) && (! break_loop); i++)
 	{
+		gint buf_len;
+
 		line_start = sci_get_position_from_line(doc_list[idx].sci, i);
 		line_len = sci_get_line_length(doc_list[idx].sci, i);
 		x = 0;
 
-		sci_get_text_range(doc_list[idx].sci, line_start, MIN((line_start + 255), (line_start + line_len - 1)), sel);
-		sel[MIN(255, (line_len - 1))] = '\0';
+		buf_len = MIN((gint)sizeof(sel) - 1, line_len - 1);
+		if (buf_len <= 0)
+			continue;
+		sci_get_text_range(doc_list[idx].sci, line_start, line_start + buf_len, sel);
+		sel[buf_len] = '\0';
 
 		while (isspace(sel[x])) x++;
 
@@ -1458,6 +1470,8 @@
 		}
 	}
 
+	SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0);
+
 	// restore selection if there is one
 	if (sel_start < sel_end)
 	{
@@ -1549,12 +1563,17 @@
 
 	for (i = first_line; (i <= last_line) && (! break_loop); i++)
 	{
+		gint buf_len;
+
 		line_start = sci_get_position_from_line(doc_list[idx].sci, i);
 		line_len = sci_get_line_length(doc_list[idx].sci, i);
 		x = 0;
 
-		sci_get_text_range(doc_list[idx].sci, line_start, MIN((line_start + 256), (line_start + line_len - 1)), sel);
-		sel[MIN(256, (line_len - 1))] = '\0';
+		buf_len = MIN((gint)sizeof(sel) - 1, line_len - 1);
+		if (buf_len <= 0)
+			continue;
+		sci_get_text_range(doc_list[idx].sci, line_start, line_start + buf_len, sel);
+		sel[buf_len] = '\0';
 
 		while (isspace(sel[x])) x++;
 

Modified: branches/geany-0.10.1/src/sciwrappers.c
===================================================================
--- branches/geany-0.10.1/src/sciwrappers.c	2007-02-08 13:08:15 UTC (rev 1260)
+++ branches/geany-0.10.1/src/sciwrappers.c	2007-02-08 13:12:48 UTC (rev 1261)
@@ -754,6 +754,7 @@
 }
 
 
+/* text will be zero terminated and must be allocated (end - start + 1) bytes */
 void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
 {
 	struct TextRange tr;

Modified: branches/geany-0.10.1/src/utils.c
===================================================================
--- branches/geany-0.10.1/src/utils.c	2007-02-08 13:08:15 UTC (rev 1260)
+++ branches/geany-0.10.1/src/utils.c	2007-02-08 13:12:48 UTC (rev 1261)
@@ -459,7 +459,7 @@
 	if (end < 0) end = 0;
 
 	// skip whitespaces between identifier and (
-	while (isspace(sci_get_char_at(sci, end))) end--;
+	while (end > 0 && isspace(sci_get_char_at(sci, end))) end--;
 
 	start = end;
 	c = 0;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list