changeset 608:e49524bc2f07

Fix trailing junk on dw_mle_export()
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 01 Oct 2006 04:40:02 +0000
parents b4cb30f47a97
children f41b7e3a54f6
files gtk/dw.c win/dw.c
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Thu Sep 28 01:42:32 2006 +0000
+++ b/gtk/dw.c	Sun Oct 01 04:40:02 2006 +0000
@@ -4211,7 +4211,7 @@
  * Grabs text from an MLE box.
  * Parameters:
  *          handle: Handle to the MLE to be queried.
- *          buffer: Text buffer to be exported.
+ *          buffer: Text buffer to be exported. MUST allow for trailing nul character.
  *          startpoint: Point to start grabbing text.
  *          length: Amount of text to be grabbed.
  */
@@ -4223,7 +4223,7 @@
 	DW_MUTEX_LOCK;
 	/* force the return value to nul in case the following tests fail */
 	if(buffer)
-		strcpy(buffer,"");
+		buffer[0] = '\0';
 #if GTK_MAJOR_VERSION > 1
 	if(GTK_IS_SCROLLED_WINDOW(handle))
 #else
@@ -4245,17 +4245,25 @@
 			if(text) /* Should this get freed? */
 			{
 				if(buffer)
-					strcpy(buffer, text);
+					memcpy(buffer, text);
 			}
 		}
 #else
 		if(tmp && GTK_IS_TEXT(tmp))
 		{
-			text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), startpoint, startpoint + length - 1);
+			text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), 0, -1);  /* get the complete contents */
 			if(text)
 			{
 				if(buffer)
-					strcpy(buffer, text);
+				{
+					len = strlen(text);
+					if(startpoint < len)
+					{
+						max = min(length, len - startpoint);
+						memcpy(buffer, &text[startpoint], max);
+						buffer[max] = '\0';
+					}
+				}
 				g_free(text);
 			}
 		}
--- a/win/dw.c	Thu Sep 28 01:42:32 2006 +0000
+++ b/win/dw.c	Sun Oct 01 04:40:02 2006 +0000
@@ -5886,7 +5886,7 @@
  * Grabs text from an MLE box.
  * Parameters:
  *          handle: Handle to the MLE to be queried.
- *          buffer: Text buffer to be exported.
+ *          buffer: Text buffer to be exported. MUST allow for trailing nul character.
  *          startpoint: Point to start grabbing text.
  *          length: Amount of text to be grabbed.
  */
@@ -5905,6 +5905,7 @@
 		max = MIN(length, len - startpoint);
 
 		memcpy(buffer, &tmpbuf[startpoint], max);
+		buffer[max] = '\0';
 	}
 
 	free(tmpbuf);