diff --git a/defs.h b/defs.h index c20fcc61..bb4003f5 100644 --- a/defs.h +++ b/defs.h @@ -52,7 +52,10 @@ #include #include #include -#include +/* Open-coding isprint(ch) et al proved more efficient than calling + * generalized libc interface. We don't *want* to do non-ASCII anyway. + */ +/* #include */ #include #include #include diff --git a/file.c b/file.c index cfdd0bb9..2af14bff 100644 --- a/file.c +++ b/file.c @@ -2456,7 +2456,7 @@ print_xattr_val(struct tcb *tcp, int failed, unsigned char *in = &buf[3 * size]; size_t i; for (i = 0; i < size; ++i) { - if (isprint(in[i])) + if (in[i] >= ' ' && in[i] <= 0x7e) *out++ = in[i]; else { #define tohex(n) "0123456789abcdef"[n] diff --git a/util.c b/util.c index 0cc43feb..84ab00eb 100644 --- a/util.c +++ b/util.c @@ -400,7 +400,16 @@ string_quote(const char *instr, char *outstr, long len, int size) /* Check for NUL-terminated string. */ if (c == eol) break; - if (!isprint(c) && !isspace(c)) { + + /* Force hex unless c is printable or whitespace */ + if (c > 0x7e) { + usehex = 1; + break; + } + /* In ASCII isspace is only these chars: "\t\n\v\f\r". + * They happen to have ASCII codes 9,10,11,12,13. + */ + if (c < ' ' && (unsigned)(c - 9) >= 5) { usehex = 1; break; } @@ -453,7 +462,7 @@ string_quote(const char *instr, char *outstr, long len, int size) *s++ = 'v'; break; default: - if (isprint(c)) + if (c >= ' ' && c <= 0x7e) *s++ = c; else { /* Print \octal */