[PATCH] fix invalid printf format strings
Rich Felker
dalias at aerifal.cx
Fri Mar 24 20:13:08 UTC 2006
On Fri, Mar 24, 2006 at 08:29:31PM +0100, Bernhard Fischer wrote:
> Hi dalias,
>
> On Fri, Mar 24, 2006 at 01:37:29PM -0500, Rich Felker wrote:
> >The attached patch changes all occurrances of %L[diouxX] to use %ll
> >instead, conforming to C99 and SUSv3. The %L width specifier was
> >intended only for use with floating types (for long double), not long
> >long, and its behavior with integer types is unspecified.
>
> No.
>
> See tail of platform.h
>
> We want make CC="cc -U_ -UN_" to dtrt, so pretty please rip them out
> while you're touching these very same lines and resend. TIA.
OK, updated patch attached. Is this better?
Rich
-------------- next part --------------
Index: networking/interface.c
===================================================================
--- networking/interface.c (revision 14622)
+++ networking/interface.c (working copy)
@@ -1038,23 +1038,23 @@
* args. */
/* static const char * const ss_fmt[] = { */
-/* "%Ln%Lu%lu%lu%lu%lu%ln%ln%Ln%Lu%lu%lu%lu%lu%lu", */
-/* "%Lu%Lu%lu%lu%lu%lu%ln%ln%Lu%Lu%lu%lu%lu%lu%lu", */
-/* "%Lu%Lu%lu%lu%lu%lu%lu%lu%Lu%Lu%lu%lu%lu%lu%lu%lu" */
+/* "%lln%llu%lu%lu%lu%lu%ln%ln%lln%llu%lu%lu%lu%lu%lu", */
+/* "%llu%llu%lu%lu%lu%lu%ln%ln%llu%llu%lu%lu%lu%lu%lu", */
+/* "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu" */
/* }; */
/* Lie about the size of the int pointed to for %n. */
#if INT_MAX == LONG_MAX
static const char * const ss_fmt[] = {
- "%n%Lu%u%u%u%u%n%n%n%Lu%u%u%u%u%u",
- "%Lu%Lu%u%u%u%u%n%n%Lu%Lu%u%u%u%u%u",
- "%Lu%Lu%u%u%u%u%u%u%Lu%Lu%u%u%u%u%u%u"
+ "%n%llu%u%u%u%u%n%n%n%llu%u%u%u%u%u",
+ "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u",
+ "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u"
};
#else
static const char * const ss_fmt[] = {
- "%n%Lu%lu%lu%lu%lu%n%n%n%Lu%lu%lu%lu%lu%lu",
- "%Lu%Lu%lu%lu%lu%lu%n%n%Lu%Lu%lu%lu%lu%lu%lu",
- "%Lu%Lu%lu%lu%lu%lu%lu%lu%Lu%Lu%lu%lu%lu%lu%lu%lu"
+ "%n%llu%lu%lu%lu%lu%n%n%n%llu%lu%lu%lu%lu%lu",
+ "%llu%llu%lu%lu%lu%lu%n%n%llu%llu%lu%lu%lu%lu%lu",
+ "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu"
};
#endif
@@ -1748,7 +1748,7 @@
#endif
} while (i);
- printf("X bytes:%Lu (%Lu.%u %sB)%s", ull, int_part, frac_part, ext, end);
+ printf("X bytes:%llu (%llu.%u %sB)%s", ull, int_part, frac_part, ext, end);
}
static const char * const ife_print_flags_strs[] = {
@@ -1989,23 +1989,23 @@
*/
printf(" ");
- printf(_("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
+ printf("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n",
ptr->stats.rx_packets, ptr->stats.rx_errors,
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
ptr->stats.rx_frame_errors);
if (can_compress)
- printf(_(" compressed:%lu\n"),
+ printf(" compressed:%lu\n",
ptr->stats.rx_compressed);
printf(" ");
- printf(_("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
+ printf("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n",
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
ptr->stats.tx_carrier_errors);
- printf(_(" collisions:%lu "), ptr->stats.collisions);
+ printf(" collisions:%lu "), ptr->stats.collisions;
if (can_compress)
- printf(_("compressed:%lu "), ptr->stats.tx_compressed);
+ printf("compressed:%lu ", ptr->stats.tx_compressed);
if (ptr->tx_queue_len != -1)
- printf(_("txqueuelen:%d "), ptr->tx_queue_len);
+ printf("txqueuelen:%d ", ptr->tx_queue_len);
printf("\n R");
print_bytes_scaled(ptr->stats.rx_bytes, " T");
print_bytes_scaled(ptr->stats.tx_bytes, "\n");
Index: coreutils/stat.c
===================================================================
--- coreutils/stat.c (revision 14622)
+++ coreutils/stat.c (working copy)
@@ -400,7 +400,7 @@
#else
format = (flags & OPT_TERSE
- ? "%s %Lx %lu "
+ ? "%s %llx %lu "
: " File: \"%s\"\n"
" ID: %-8Lx Namelen: %-7lu ");
printf(format,
Index: libbb/human_readable.c
===================================================================
--- libbb/human_readable.c (revision 14622)
+++ libbb/human_readable.c (working copy)
@@ -33,8 +33,8 @@
{
/* The code will adjust for additional (appended) units. */
static const char zero_and_units[] = { '0', 0, 'k', 'M', 'G', 'T' };
- static const char fmt[] = "%Lu";
- static const char fmt_tenths[] = "%Lu.%d%c";
+ static const char fmt[] = "%llu";
+ static const char fmt_tenths[] = "%llu.%d%c";
static char str[21]; /* Sufficient for 64 bit unsigned integers. */
@@ -74,7 +74,7 @@
if ( frac >= 5 ) {
++val;
}
- f = "%Lu%*c" /* fmt_no_tenths */ ;
+ f = "%llu%*c" /* fmt_no_tenths */ ;
frac = 1;
}
#endif
Index: e2fsprogs/blkid/blkid_getsize.c
===================================================================
--- e2fsprogs/blkid/blkid_getsize.c (revision 14622)
+++ e2fsprogs/blkid/blkid_getsize.c (working copy)
@@ -173,7 +173,7 @@
perror(argv[0]);
bytes = blkid_get_dev_size(fd);
- printf("Device %s has %Ld 1k blocks.\n", argv[1], bytes >> 10);
+ printf("Device %s has %lld 1k blocks.\n", argv[1], bytes >> 10);
return 0;
}
More information about the busybox
mailing list