SF.net SVN: geany: [497] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Tue Jun 27 20:43:09 UTC 2006


Revision: 497
Author:   eht16
Date:     2006-06-27 13:43:04 -0700 (Tue, 27 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=497&view=rev

Log Message:
-----------
Fixed a crash when auto completion or call tips are used if no filetype was set. Added some sanity checks.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/sci_cb.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-06-27 17:07:22 UTC (rev 496)
+++ trunk/ChangeLog	2006-06-27 20:43:04 UTC (rev 497)
@@ -6,6 +6,8 @@
    Add support for parsing compiler output for LaTeX with latex's
    --file-line-error-style command line argument.
    Removed unneeded function utils_free_ptr_array().
+ * src/sci_cb.c: Fixed a crash when auto completion or call tips are
+                 used if no filetype was set. Added some sanity checks.
 
 
 2006-06-27  Nick Treleaven  <nick.treleaven at btinternet.com>

Modified: trunk/src/sci_cb.c
===================================================================
--- trunk/src/sci_cb.c	2006-06-27 17:07:22 UTC (rev 496)
+++ trunk/src/sci_cb.c	2006-06-27 20:43:04 UTC (rev 497)
@@ -359,7 +359,8 @@
 	
 	lexer = SSM(sci, SCI_GETLEXER, 0, 0);
 	idx = document_find_by_sci(sci);
-
+	if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return FALSE;
+	
 	word[0] = '\0';
 	if (pos == -1)
 	{	// position of '(' is unknown, so go backwards to find it
@@ -388,16 +389,8 @@
 
 gboolean sci_cb_start_auto_complete(ScintillaObject *sci, gint pos)
 {
-	gint line = sci_get_line_from_position(sci, pos);
-	gint line_start = sci_get_position_from_line(sci, line);
-	gint line_len = sci_get_line_length(sci, line);
-	gint line_pos = pos - line_start - 1;
-	gint current = pos - line_start;
-	gint rootlen;
-	gint startword = current, lexer = SSM(sci, SCI_GETLEXER, 0, 0);
-	gint style = SSM(sci, SCI_GETSTYLEAT, pos, 0);
-	gchar linebuf[line_len + 1];
-	gchar *root;
+	gint line, line_start, line_len, line_pos, current, rootlen, startword, lexer, style;
+	gchar *linebuf, *root;
 	const GPtrArray *tags;
 
 	if (sci == NULL) return FALSE;
@@ -407,7 +400,8 @@
 	line_len = sci_get_line_length(sci, line);
 	line_pos = pos - line_start - 1;
 	current = pos - line_start;
-	startword = current, lexer = SSM(sci, SCI_GETLEXER, 0, 0);
+	startword = current;
+	lexer = SSM(sci, SCI_GETLEXER, 0, 0);
 	style = SSM(sci, SCI_GETSTYLEAT, pos, 0);
 
 	//if (lexer != SCLEX_CPP && lexer != SCLEX_HTML && lexer != SCLEX_PASCAL) return FALSE;
@@ -415,6 +409,7 @@
 	if (lexer == SCLEX_CPP && (style == SCE_C_COMMENT ||
 			style == SCE_C_COMMENTLINE || style == SCE_C_COMMENTDOC)) return FALSE;
 
+	linebuf = g_malloc(line_len + 1);
 	sci_get_line(sci, line, linebuf);
 
 	// find the start of the current word
@@ -448,8 +443,18 @@
 		gint idx = document_find_by_sci(sci);
 		TMTagAttrType attrs[] = { tm_tag_attr_name_t, 0 };
 
+		if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL)
+		{	// go home if typed less than 4 chars
+			g_free(linebuf);
+			return FALSE;
+		}
+
 		while ((line_pos - i >= 0) && ! g_ascii_isspace(linebuf[line_pos - i])) i++;
-		if (i < 4) return FALSE;	// go home if typed less than 4 chars
+		if (i < 4)
+		{	// go home if typed less than 4 chars
+			g_free(linebuf);
+			return FALSE;
+		}
 
 		tags = tm_workspace_find(root, tm_tag_max_t, attrs, TRUE, doc_list[idx].file_type->lang);
 		if (NULL != tags && tags->len > 0)
@@ -467,6 +472,7 @@
 			g_string_free(words, TRUE);
 		}
 	}
+	g_free(linebuf);
 	return TRUE;
 }
 


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