From 7b4275cae8d2f53f2496f391bdf56b76a6392f2c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 28 Aug 2005 23:05:14 +0000 Subject: 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@ --- lib/libc/gen/vis.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/libc') 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; ) { -- cgit v1.2.3