From ee8926503c8f451ffbdb00760388e17edde343cb Mon Sep 17 00:00:00 2001 From: Francisco Couzo Date: Wed, 17 Jan 2018 21:59:03 -0300 Subject: Prevent undefined behaviour on memcpy --- src/fe-gtk/xtext.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c index 35242fe0..6151f5b6 100644 --- a/src/fe-gtk/xtext.c +++ b/src/fe-gtk/xtext.c @@ -4677,9 +4677,11 @@ gtk_xtext_append_indent (xtext_buffer *buf, ent = g_malloc (left_len + right_len + 2 + sizeof (textentry)); str = (unsigned char *) ent + sizeof (textentry); - memcpy (str, left_text, left_len); + if (left_len) + memcpy (str, left_text, left_len); str[left_len] = ' '; - memcpy (str + left_len + 1, right_text, right_len); + if (right_len) + memcpy (str + left_len + 1, right_text, right_len); str[left_len + 1 + right_len] = 0; left_width = gtk_xtext_text_width (buf->xtext, left_text, left_len); -- cgit 1.4.1