From b05472eb9d05ac659c1657eefabdfc1aeed4e3bb Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Thu, 8 Nov 2018 17:11:07 +0000 Subject: [PATCH] elm code - warn - explicit truncation via custom truncate func --- src/lib/elementary/elm_code_widget_selection.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c index cf5f355009..31476ca4ad 100644 --- a/src/lib/elementary/elm_code_widget_selection.c +++ b/src/lib/elementary/elm_code_widget_selection.c @@ -202,6 +202,18 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widge free(selection); } +static void +my_string_copy_truncate(char *dest, const char *src, size_t len) +{ + char *p; + for (p = dest; len > 0; p++, src++, len--) + { + *p = *src; + if (*src == 0) break; + } +} + + static void _elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { @@ -232,9 +244,11 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget if (last_length > 0) { if (end == last_length) - strncpy(content + start, last + end, last_length - end); + my_string_copy_truncate(content + start, last + end, + last_length - end); else - strncpy(content + start, last + end + 1, last_length - (end + 1)); + my_string_copy_truncate(content + start, last + end + 1, + last_length - (end + 1)); } for (i = line->number; i > selection->start_line; i--)