Subject: Re: bug#19184: coreutils-8.23 Compile Error on Solaris 8 - Sun Studio 11

From: Pádraig Brady <[email-masked]>
Date: Thu, 27 Nov 2014 01:10:45 +0000

On 26/11/14 20:37, Pádraig Brady wrote:
> The other issue is incorrect prompts output by rm due to its use of %zu
> Ted could you give the output of:
> 
>   grep gl_cv_func_printf_sizes_c99 config.log
> 
> Now coreutils doesn't make use of the fprintf-posix module
> to act on the above test.
> Jim attempted it for a day in 2007 but reverted due to "too many test failures".
> We could easily avoid the use of %zu I suppose in coreutils,
> as there are only a few uses really.

I did that in the attached.

thanks,
Pádraig
>From 78202c7118378cf1886f46887412dbf49ce3a1cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Thu, 27 Nov 2014 00:51:00 +0000
Subject: [PATCH] rm: fix prompted number of arguments to remove on some
 platforms

"zu" was output on solaris 8 for example rather than the number,
since coreutils-8.22.

* cfg.mk: Disallow %zu with fprintf() since we make minimal
use of this function and so don't employ the gnulib replacement.
* src/rm.c (main): Use %PRIuMAX rather than %zu for portability.
* NEWS: Mention the bug fix.
Reported in http://bugs.gnu.org/19184
---
 NEWS     |  3 +++
 cfg.mk   |  9 +++++++++
 src/rm.c | 10 +++++-----
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 27847d4..3a62656 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   character at the 4GiB position.
   [the bug dates back to the initial implementation]
 
+  rm indicates the correct number of arguments in its confirmation prompt,
+  on all platforms.  [bug introduced in coreutils-8.22]
+
 ** New features
 
   chroot accepts the new --skip-chdir option to not change the working directory
diff --git a/cfg.mk b/cfg.mk
index 7347322..c6fc0e7 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -223,6 +223,15 @@ sc_prohibit-j-printf-format:
 	  && { echo '$(ME): Use PRI*MAX instead of %j' 1>&2; exit 1; }  \
 	  || :
 
+# coreutils doesn't use any fprintf gnulib replacement since we
+# make minimal use of fprintf, to output prompt strings mainly.
+# Here we disallow %zu with fprintf() as that's not portable to
+# Solaris 8 for example.
+sc_prohibit-z-fprintf-format:
+	@cd $(srcdir)/src && GIT_PAGER= git grep -A4 ' fprintf (' | grep %zu \
+	  && { echo '$(ME): Use PRI*MAX instead of %z' 1>&2; exit 1; }	     \
+	  || :
+
 # Ensure the alternative __attribute (keyword) form isn't used as
 # that form is not elided where required.  Also ensure that we don't
 # directly use attributes already defined by gnulib.
diff --git a/src/rm.c b/src/rm.c
index f7adf5b..4c8ee6e 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -332,18 +332,18 @@ main (int argc, char **argv)
                quote ("/"));
     }
 
-  size_t n_files = argc - optind;
+  uintmax_t n_files = argc - optind;
   char **file =  argv + optind;
 
   if (prompt_once && (x.recursive || 3 < n_files))
     {
       fprintf (stderr,
                (x.recursive
-                ? ngettext ("%s: remove %zu argument recursively? ",
-                            "%s: remove %zu arguments recursively? ",
+                ? ngettext ("%s: remove %"PRIuMAX" argument recursively? ",
+                            "%s: remove %"PRIuMAX" arguments recursively? ",
                             select_plural (n_files))
-                : ngettext ("%s: remove %zu argument? ",
-                            "%s: remove %zu arguments? ",
+                : ngettext ("%s: remove %"PRIuMAX" argument? ",
+                            "%s: remove %"PRIuMAX" arguments? ",
                             select_plural (n_files))),
                program_name, n_files);
       if (!yesno ())
-- 
2.1.0