From b3634d74b02e7ef69371fa65a92f4db1a3ff7bac Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Mon, 24 Feb 2025 20:46:49 +0000 Subject: [PATCH] Handle multibyte mode line spec chars (bug#76517) * src/xdisp.c (display_mode_element): Make 'c' an 'int'. Use 'string_char_and_length' to fetch the character from a multibyte string, not 'SREF'. (cherry picked from commit 1f891898d490380ea59f21fa8ea4e7f7364a1a79) --- src/xdisp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/xdisp.c b/src/xdisp.c index a7124d02044..dc2e1c168fb 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -27755,7 +27755,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision, case Lisp_String: { /* A string: output it and check for %-constructs within it. */ - unsigned char c; + int c; ptrdiff_t offset = 0; if (SCHARS (elt) > 0 @@ -27926,6 +27926,15 @@ display_mode_element (struct it *it, int depth, int field_width, int precision, while ((c = SREF (elt, offset++)) >= '0' && c <= '9') field = field * 10 + c - '0'; + /* "%" could be followed by a multibyte character. */ + if (STRING_MULTIBYTE (elt)) + { + int length; + offset--; + c = string_char_and_length (SDATA (elt) + offset, &length); + offset += length; + } + /* Don't pad beyond the total padding allowed. */ if (field_width - n > 0 && field > field_width - n) field = field_width - n; -- 2.39.5