From 63879a0d63d4096155f14b1d668316ef8ed1a566 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Apr 2026 16:40:55 +0200 Subject: [PATCH] event-widget: Truncate long strings by char not by bytes Longer text were truncated by bytes instead of chars leading to invalid text as UTF text sizes are bigger than one byte. Fix it by using the correct utf8 offset pointer. Part-of: --- src/gui/gcal-event-widget.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/gcal-event-widget.c b/src/gui/gcal-event-widget.c index 99603fc6..3174c056 100644 --- a/src/gui/gcal-event-widget.c +++ b/src/gui/gcal-event-widget.c @@ -391,7 +391,8 @@ gcal_event_widget_set_event_tooltip (GcalEventWidget *self, if (truncated_location->len > LOCATION_MAX_LEN) { - g_string_truncate (truncated_location, LOCATION_MAX_LEN - 1); + char *cut = g_utf8_offset_to_pointer (truncated_location->str, LOCATION_MAX_LEN - 1); + g_string_truncate (truncated_location, cut - truncated_location->str); g_string_append (truncated_location, "…"); } @@ -423,7 +424,8 @@ gcal_event_widget_set_event_tooltip (GcalEventWidget *self, /* If the description is larger than DESC_MAX_CHAR, ellipsize it */ if (description_len > DESC_MAX_CHAR) { - g_string_truncate (tooltip_desc, DESC_MAX_CHAR - 1); + char *cut = g_utf8_offset_to_pointer (tooltip_desc->str, DESC_MAX_CHAR - 1); + g_string_truncate (tooltip_desc, cut - tooltip_desc->str); g_string_append (tooltip_desc, "…"); }