From e5d7764386c173a37106002c6bc800866d4125e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sat, 18 Oct 2025 13:02:44 +0100 Subject: [PATCH 5/6] numfmt: use multi-byte aware suffix matching * src/numfmt.c (process_suffixed_number): Use gnulib's mbs_endswith() helper, which is more robust in non UTF-8 locales. Also always output a devmsg if a suffix is specified. --- bootstrap.conf | 1 + src/numfmt.c | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index f470aa48b..8f9194341 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -173,6 +173,7 @@ gnulib_modules=" mbrlen mbrtoc32 mbrtowc + mbs_endswith mbschr mbslen mbswidth diff --git a/src/numfmt.c b/src/numfmt.c index 67458558a..cc80ccc5d 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -1326,14 +1326,11 @@ static int process_suffixed_number (char *text, long double *result, size_t *precision, long int field) { - if (suffix && strlen (text) > strlen (suffix)) + if (suffix) { - char *possible_suffix = text + strlen (text) - strlen (suffix); - - if (streq (suffix, possible_suffix)) + if (mbs_endswith (text, suffix)) { - /* trim suffix, ONLY if it's at the end of the text. */ - *possible_suffix = '\0'; + *(text + strlen (text) - strlen (suffix)) = '\0'; devmsg ("trimming suffix %s\n", quote (suffix)); } else -- 2.51.0