summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2018-02-11 17:24:32 -0500
committerPatrick Griffis <tingping@tingping.se>2018-02-11 17:24:32 -0500
commit7510ab36b714c70366855e72a481ab6c97d0c9c8 (patch)
tree134803b539bf704bb32908d4a8fd7b04864b1dea /src
parentd3f1ab78138a1f9256ec02842799ed6cd1e3ec1e (diff)
xtext: Fix accidental truncation
Fixes #2121
Diffstat (limited to 'src')
-rw-r--r--src/fe-gtk/xtext.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index 203bcd60..8ca24a12 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -4729,6 +4729,7 @@ void
 gtk_xtext_append (xtext_buffer *buf, unsigned char *text, int len, time_t stamp)
 {
 	textentry *ent;
+	gboolean truncate = FALSE;
 
 	if (len == -1)
 		len = strlen (text);
@@ -4737,12 +4738,27 @@ gtk_xtext_append (xtext_buffer *buf, unsigned char *text, int len, time_t stamp)
 		len--;
 
 	if (len >= sizeof (buf->xtext->scratch_buffer))
+	{
 		len = sizeof (buf->xtext->scratch_buffer) - 1;
+		truncate = TRUE;
+	}
 
 	ent = g_malloc (len + 1 + sizeof (textentry));
 	ent->str = (unsigned char *) ent + sizeof (textentry);
-	safe_strcpy (ent->str, text, len);
-	ent->str_len = strlen (ent->str); /* Possibly truncated */
+	ent->str_len = len;
+	if (len)
+	{
+		if (!truncate)
+		{
+			memcpy (ent->str, text, len);
+			ent->str[len] = '\0';
+		}
+		else
+		{
+			safe_strcpy (ent->str, text, sizeof (buf->xtext->scratch_buffer));
+			ent->str_len = strlen (ent->str);
+		}
+	}
 	ent->indent = 0;
 	ent->left_len = -1;