[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] od: print valid octal values with -c flag
From: Ron Yorston <rmy () tigress ! co ! uk>
Date: 2014-03-20 21:43:23
Message-ID: 201403202143.s2KLhN9x032312 () helium ! internal ! tigress ! co ! uk
[Download RAW message or body]
For characters with the top bit set od_bloaty produces silly octal
values with the -c flag:
$ echo £ | busybox od -c # od_bloaty.c (CONFIG_DESKTOP set)
0000000 0H2 0D3 \n
0000003
$ echo £ | busybox od -c # od.c (CONFIG_DESKTOP not set)
0000000 302 243 \n
0000003
$ echo £ | od -c # coreutils
0000000 302 243 \n
0000003
Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
---
coreutils/od_bloaty.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 2c26dda..337d132 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -387,8 +387,8 @@ print_named_ascii(size_t n_bytes, const char *block,
" sp"
};
// buf[N] pos: 01234 56789
- char buf[12] = " x\0 0xx\0";
- // actually " x\0 xxx\0", but want to share string with print_ascii.
+ char buf[12] = " x\0 xxx\0";
+ // share string with print_ascii.
// [12] because we take three 32bit stack slots anyway, and
// gcc is too dumb to initialize with constant stores,
// it copies initializer from rodata. Oh well.
@@ -419,7 +419,7 @@ print_ascii(size_t n_bytes, const char *block,
const char *unused_fmt_string UNUSED_PARAM)
{
// buf[N] pos: 01234 56789
- char buf[12] = " x\0 0xx\0";
+ char buf[12] = " x\0 xxx\0";
while (n_bytes--) {
const char *s;
@@ -458,8 +458,9 @@ print_ascii(size_t n_bytes, const char *block,
case '\x7f':
s = " 177";
break;
- default: /* c is never larger than 040 */
- buf[7] = (c >> 3) + '0';
+ default:
+ buf[6] = (c >> 6 & 3) + '0';
+ buf[7] = (c >> 3 & 7) + '0';
buf[8] = (c & 7) + '0';
s = buf + 5;
}
--
1.8.5.3
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic