aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-08 00:47:05 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-08 00:47:05 -0500
commita16fad96ea5de993cca61753198db43789156c7e (patch)
tree30f1341e82d8404a02ce1e01bdef516bf52af564
parentlibsandbox: let real funcs handle non-existent paths (part 2) (diff)
downloadsandbox-a16fad96ea5de993cca61753198db43789156c7e.tar.gz
sandbox-a16fad96ea5de993cca61753198db43789156c7e.tar.bz2
sandbox-a16fad96ea5de993cca61753198db43789156c7e.zip
sb_printf: get z modifier working and fixup tests
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--libsbutil/sb_printf.c12
-rw-r--r--tests/sb_printf.at87
-rw-r--r--tests/sb_printf_tst.c9
3 files changed, 45 insertions, 63 deletions
diff --git a/libsbutil/sb_printf.c b/libsbutil/sb_printf.c
index 8756a91..2270ece 100644
--- a/libsbutil/sb_printf.c
+++ b/libsbutil/sb_printf.c
@@ -46,7 +46,6 @@ void sb_vfdprintf(int fd, const char *format, va_list args)
char buf[50];
size_t idx;
- int i;
unsigned int u, x;
char hex_base;
size_t padding = 0;
@@ -97,7 +96,11 @@ void sb_vfdprintf(int fd, const char *format, va_list args)
case 'd':
case 'i': {
- i = va_arg(args, int);
+ long i;
+ if (modifiers & MOD_SIZE_T)
+ i = va_arg(args, ssize_t);
+ else
+ i = va_arg(args, int);
u = i;
if (i < 0) {
sb_write(fd, "-", 1);
@@ -125,7 +128,10 @@ void sb_vfdprintf(int fd, const char *format, va_list args)
case 'x': {
hex_base = 'a';
out_hex:
- x = va_arg(args, unsigned int);
+ if (modifiers & MOD_SIZE_T)
+ x = va_arg(args, size_t);
+ else
+ x = va_arg(args, unsigned int);
out_ptr:
idx = 0;
do {
diff --git a/tests/sb_printf.at b/tests/sb_printf.at
index 33a17b0..baa47b6 100644
--- a/tests/sb_printf.at
+++ b/tests/sb_printf.at
@@ -1,62 +1,33 @@
AT_SETUP(sb_printf)
-AT_CHECK([sb_printf_tst], [0], [dnl
-1
--1
-123
--123
-1000
-1
--1
-123
--123
-1000
-0x1
-0xabcdef
-0x1
-0xABCDEF
-a
-0
-K
-wOOf
-CoW
-!HI!
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre} cow{post}
-{pre} cow{post}
-%
-0x0000000000123456
-1
--1
-123
--123
-1000
-1
-4294967295
-123
-4294967173
-1000
-1
-abcdef
-1
-ABCDEF
-a
-0
-K
-wOOf
-CoW
-!HI!
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre}cow{post}
-{pre} cow{post}
-{pre} cow{post}
-%
-0x123456
-])
+AT_CHECK([dnl
+sb_printf_tst | awk 'BEGIN { ret = 0 }
+{
+ if (G == "") {
+ G = $0
+ next
+ }
+ glibc = G
+ G = ""
+
+ # easy case -- glibc output matches our output
+ if (glibc == $0)
+ next
+ # not so easy -- we format sandbox printf() the way we like
+
+ # %x -- we prefix output with 0x
+ if ($1 ~ /%[[xX]]/)
+ gsub(/\<0x/, "")
+
+ # %p -- we zero pad the output
+ if ($1 ~ /%p/)
+ gsub(/\<0x0+/, "0x")
+
+ if (glibc == $0)
+ next
+ printf "FAIL:\nglibc:%s\nsandbox:%s\n", glibc, $0
+ ret = 1
+}
+END { exit ret }'], [0])
AT_CLEANUP
diff --git a/tests/sb_printf_tst.c b/tests/sb_printf_tst.c
index 71a38aa..d189a30 100644
--- a/tests/sb_printf_tst.c
+++ b/tests/sb_printf_tst.c
@@ -1,14 +1,19 @@
#include "headers.h"
#include "sbutil.h"
+#define _T(func, fmt, args...) func("%i:[%s] " fmt "\n", __LINE__, fmt, ##args)
#define T(fmt, args...) \
do { \
- printf("%i: " fmt "\n", __LINE__, ##args); \
- sb_printf("%i: " fmt "\n", __LINE__, ##args); \
+ _T(printf, fmt, ## args); \
+ _T(sb_printf, fmt, ## args); \
} while (0)
int main(int argc, char *argv[])
{
+ /* sandbox outputs to stderr, so unify it */
+ dup2(STDOUT_FILENO, STDERR_FILENO);
+ setbuf(stdout, NULL);
+
T("%i", argc);
T("%i", -argc);
T("%d", 123);