[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: coreutils-5.90 released
Re: coreutils-5.90 released
Fri, 30 Sep 2005 18:28:25 +0200
Paul Eggert <address@hidden> wrote:
> address@hidden (Eric Blake) writes:
>> dd.c:1661: warning: long unsigned int format, size_t arg (arg 5)
> Thanks; I installed this patch.
> Jim -- I'm not sure what version number you want at the top of
> ChangeLog so I left it out for now.
I've taken care of that. 5.91-cvs.
> 2005-09-29 Paul Eggert <address@hidden>
> * src/dd.c (main): Don't assume size_t has the same width
> as unsigned long. Problem reported by Eric Blake.
> --- src/dd.c 16 Sep 2005 09:35:47 -0000 1.187
> +++ src/dd.c 30 Sep 2005 05:07:11 -0000 1.188
> @@ -1652,13 +1652,14 @@ main (int argc, char **argv)
> if (seek_records != 0 && !(conversions_mask & C_NOTRUNC))
> uintmax_t size = seek_records * output_blocksize;
> + unsigned long int obs = output_blocksize;
> if (OFF_T_MAX / output_blocksize < seek_records)
> error (EXIT_FAILURE, 0,
> _("offset too large: "
> "cannot truncate to a length of seek=%"PRIuMAX""
> " (%lu-byte) blocks"),
> - seek_records, output_blocksize);
> + seek_records, obs);
> if (ftruncate (STDOUT_FILENO, size) != 0)
I think it's about time we started using a format string for size_t values,
rather than trying to shoe-horn them into some other format.
How about something like this:
RCS file: /fetish/cu/src/dd.c,v
retrieving revision 1.188
diff -u -p -r1.188 dd.c
--- dd.c 30 Sep 2005 05:07:11 -0000 1.188
+++ dd.c 30 Sep 2005 07:39:33 -0000
@@ -1652,14 +1652,13 @@ main (int argc, char **argv)
if (seek_records != 0 && !(conversions_mask & C_NOTRUNC))
uintmax_t size = seek_records * output_blocksize;
- unsigned long int obs = output_blocksize;
if (OFF_T_MAX / output_blocksize < seek_records)
error (EXIT_FAILURE, 0,
_("offset too large: "
"cannot truncate to a length of seek=%"PRIuMAX""
- " (%lu-byte) blocks"),
- seek_records, obs);
+ " (%"PRI_z"-byte) blocks"),
+ seek_records, output_blocksize);
if (ftruncate (STDOUT_FILENO, size) != 0)
Then we need to define PRI_z.
Probably need an autoconf test, but this might just do, assuming
the needed symbols are always defined.
I deliberately omitted unsigned long long, on the presumption
that that type has the same size as either unsigned long or uintmax_t,
and because it's a little trickier. Does anyone know of a system
where that's not true?
RCS file: /fetish/cu/src/system.h,v
retrieving revision 1.137
diff -u -p -r1.137 system.h
--- system.h 28 Sep 2005 22:11:06 -0000 1.137
+++ system.h 30 Sep 2005 15:28:31 -0000
@@ -57,6 +57,17 @@ you must include <sys/types.h> before in
+/* Determine a printf conversion specifier that is appropriate for size_t.
+ Ideally, we'd just use the c99-specified `z' length modifier, defining
+ PRI_z to "zu", but that's not portable. */
+#if SIZE_MAX == UINT_MAX
+# define PRI_z "u"
+#elif SIZE_MAX == ULONG_MAX
+# define PRI_z "lu"
+# define PRI_z PRIuMAX
# include <sys/time.h>
# include <time.h>