summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-03-13 22:21:33 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-03-13 22:21:33 +0000
commitd425cb50920de1d49c8ece20efb58157a0cfb7cf (patch)
treee726addb89ebfa62f4a5a174089b87a5aa5719c3 /lib/libc/gen
parent2c8b13a194717b959549c7063f797b71811d193e (diff)
Fix handling of VIS_ALL: in vis(), actually encode all characters
as requested and give a correct estimate when they don't all fit, and in unvis() decode them instead of erroring ok nicm@, deraadt@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/unvis.c6
-rw-r--r--lib/libc/gen/vis.c11
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c
index d00d527b5aa..8982ca50647 100644
--- a/lib/libc/gen/unvis.c
+++ b/lib/libc/gen/unvis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unvis.c,v 1.14 2010/08/24 23:49:06 djm Exp $ */
+/* $OpenBSD: unvis.c,v 1.15 2011/03/13 22:21:32 guenther Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -73,6 +73,10 @@ unvis(char *cp, char c, int *astate, int flag)
case S_START:
switch(c) {
+ case '-':
+ *cp = 0;
+ *astate = S_GROUND;
+ return (0);
case '\\':
*cp = c;
*astate = S_GROUND;
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
index 83227d96705..a1f4b0fd8b8 100644
--- a/lib/libc/gen/vis.c
+++ b/lib/libc/gen/vis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vis.c,v 1.21 2010/08/24 23:49:06 djm Exp $ */
+/* $OpenBSD: vis.c,v 1.22 2011/03/13 22:21:32 guenther Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,7 +35,8 @@
#include <vis.h>
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define isvisible(c) \
+#define isvisible(c,flag) \
+ (((c) == '\\' || (flag & VIS_ALL) == 0) && \
(((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
(((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \
(flag & VIS_GLOB) == 0) && isgraph((u_char)(c))) || \
@@ -44,7 +45,7 @@
((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
@@ -52,7 +53,7 @@
char *
vis(char *dst, int c, int flag, int nextc)
{
- if (isvisible(c) && (flag & VIS_ALL) == 0) {
+ if (isvisible(c, flag)) {
*dst++ = c;
if (c == '\\' && (flag & VIS_NOSLASH) == 0)
*dst++ = '\\';
@@ -167,7 +168,7 @@ strnvis(char *dst, const char *src, size_t siz, int flag)
i = 0;
for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
- if (isvisible(c)) {
+ if (isvisible(c, flag)) {
i = 1;
*dst++ = c;
if (c == '\\' && (flag & VIS_NOSLASH) == 0) {