]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
numfmt: use multi-byte aware suffix matching
authorPádraig Brady <P@draigBrady.com>
Sat, 18 Oct 2025 12:02:44 +0000 (13:02 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 18 Oct 2025 19:03:57 +0000 (20:03 +0100)
* 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
src/numfmt.c

index f470aa48b31eff69cd396cc85b4cdea78e755fff..8f91943417c0e333fe5a223868ab624bb0e9c4ad 100644 (file)
@@ -173,6 +173,7 @@ gnulib_modules="
   mbrlen
   mbrtoc32
   mbrtowc
+  mbs_endswith
   mbschr
   mbslen
   mbswidth
index 67458558a747d6f9f724882fcc7d2e066a88bf9e..cc80ccc5d85e733d0c8ace7a455e932680fd85dd 100644 (file)
@@ -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