svn commit: trunk/busybox: coreutils testsuite
vda at busybox.net
vda at busybox.net
Fri Jul 18 18:41:55 UTC 2008
Author: vda
Date: 2008-07-18 11:41:55 -0700 (Fri, 18 Jul 2008)
New Revision: 22879
Log:
printf: do not print garbage on "%Ld". closes bug 4214.
function old new delta
printf_main 633 637 +4
multiconvert 99 79 -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-20) Total: -16 bytes
Modified:
trunk/busybox/coreutils/printf.c
trunk/busybox/testsuite/printf.tests
Changeset:
Modified: trunk/busybox/coreutils/printf.c
===================================================================
--- trunk/busybox/coreutils/printf.c 2008-07-18 18:17:10 UTC (rev 22878)
+++ trunk/busybox/coreutils/printf.c 2008-07-18 18:41:55 UTC (rev 22879)
@@ -63,11 +63,8 @@
static int multiconvert(const char *arg, void *result, converter convert)
{
- char s[sizeof(int)*3 + 2];
-
if (*arg == '"' || *arg == '\'') {
- sprintf(s, "%d", (unsigned char)arg[1]);
- arg = s;
+ arg = utoa((unsigned char)arg[1]);
}
errno = 0;
convert(arg, result);
@@ -289,10 +286,22 @@
}
}
}
+ /* Remove size modifiers - "%Ld" would try to printf
+ * long long, we pass long, and it spews garbage */
if ((*f | 0x20) == 'l' || *f == 'h' || *f == 'z') {
- ++f;
- ++direc_length;
+ strcpy(f, f + 1);
}
+//FIXME: actually, the same happens with bare "%d":
+//it printfs an int, but we pass long!
+//What saves us is that on most arches stack slot
+//is pointer-sized -> long-sized -> ints are promoted to longs
+// for variadic functions -> printf("%d", int_v) is in reality
+// indistinqushable from printf("%d", long_v) ->
+// since printf("%d", int_v) works, printf("%d", long_v) has to work.
+//But "clean" solution would be to add "l" to d,i,o,x,X.
+//Probably makes sense to go all the way to "ll" then.
+//Coreutils support long long-sized arguments.
+
/* needed - try "printf %" without it */
if (!strchr("diouxXfeEgGcs", *f)) {
bb_error_msg("%s: invalid format", direc_start);
Modified: trunk/busybox/testsuite/printf.tests
===================================================================
--- trunk/busybox/testsuite/printf.tests 2008-07-18 18:17:10 UTC (rev 22878)
+++ trunk/busybox/testsuite/printf.tests 2008-07-18 18:41:55 UTC (rev 22879)
@@ -74,6 +74,11 @@
"-5\n""0\n" \
"" ""
+testing "printf understands %Ld" \
+ "${bb}printf '%Ld\n' -5 2>&1; echo \$?" \
+ "-5\n""0\n" \
+ "" ""
+
# We are "more correct" here than bash/coreutils: they happily print -2
# as if it is a huge unsigned number
testing "printf handles %u -N" \
More information about the busybox-cvs
mailing list