diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2005-08-28 23:05:14 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2005-08-28 23:05:14 +0000 |
commit | 7b4275cae8d2f53f2496f391bdf56b76a6392f2c (patch) | |
tree | 26182db72a8640d6dd5a6d3488dc3c2245fe2cd2 | |
parent | 1338b81e6f06713320ba4341fe586a1652cd1c87 (diff) |
Fix the VIS_GLOB checks added in rev 1.16
Add missing casts to u_char so 0xff is treated the same on machines
with signed and unsigned chars.
OK deraadt@ espie@
-rw-r--r-- | lib/libc/gen/vis.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index f56090bfb85..d7fc4b5cf9c 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vis.c,v 1.16 2005/08/09 19:38:31 millert Exp $ */ +/* $OpenBSD: vis.c,v 1.17 2005/08/28 23:05:13 millert Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -36,16 +36,15 @@ #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define isvisible(c) \ - (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c))) && \ - (((((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \ - (flag & VIS_GLOB) == 0) && \ - isgraph((u_char)(c))) || \ + (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ + (((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \ + (flag & VIS_GLOB) == 0) && isgraph((u_char)(c))) || \ ((flag & VIS_SP) == 0 && (c) == ' ') || \ ((flag & VIS_TAB) == 0 && (c) == '\t') || \ ((flag & VIS_NL) == 0 && (c) == '\n') || \ ((flag & VIS_SAFE) && ((c) == '\b' || \ (c) == '\007' || (c) == '\r' || \ - isgraph((u_char)(c)))))) + isgraph((u_char)(c))))) /* * vis - visually encode characters @@ -105,7 +104,7 @@ vis(char *dst, int c, int flag, int nextc) goto done; } } - if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) { + if (((c & 0177) == ' ') || isgraph((u_char)c) || (flag & VIS_OCTAL)) { *dst++ = '\\'; *dst++ = ((u_char)c >> 6 & 07) + '0'; *dst++ = ((u_char)c >> 3 & 07) + '0'; @@ -118,7 +117,7 @@ vis(char *dst, int c, int flag, int nextc) c &= 0177; *dst++ = 'M'; } - if (iscntrl(c)) { + if (iscntrl((u_char)c)) { *dst++ = '^'; if (c == 0177) *dst++ = '?'; @@ -161,10 +160,9 @@ strvis(char *dst, const char *src, int flag) int strnvis(char *dst, const char *src, size_t siz, int flag) { - char c; char *start, *end; char tbuf[5]; - int i; + int c, i; i = 0; for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { |