diff options
author | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-05-07 14:31:28 +0000 |
---|---|---|
committer | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-05-07 14:31:28 +0000 |
commit | f5eeaf373b1b683f5a146cb395144eacfe1e7f7a (patch) | |
tree | 382d4d4114c060e1329700b910aad8562e1792a7 /usr.bin | |
parent | 423f9a87a7686dd8594c3bd145d28d47ef5721b2 (diff) |
Fix the \x escape sequence to be limited to max 2 characters, instead of
consuming as long as there are isxdigit(3) characters available.
While here document it and mark it as an extension.
OK millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/printf/printf.1 | 12 | ||||
-rw-r--r-- | usr.bin/printf/printf.c | 12 |
2 files changed, 13 insertions, 11 deletions
diff --git a/usr.bin/printf/printf.1 b/usr.bin/printf/printf.1 index 73ea4645a60..37e2697810f 100644 --- a/usr.bin/printf/printf.1 +++ b/usr.bin/printf/printf.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: printf.1,v 1.34 2020/01/16 16:46:47 schwarze Exp $ +.\" $OpenBSD: printf.1,v 1.35 2021/05/07 14:31:27 martijn Exp $ .\" .\" Copyright (c) 1989, 1990 The Regents of the University of California. .\" All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)printf.1 5.11 (Berkeley) 7/24/91 .\" -.Dd $Mdocdate: January 16 2020 $ +.Dd $Mdocdate: May 7 2021 $ .Dt PRINTF 1 .Os .Sh NAME @@ -103,6 +103,11 @@ Write a backslash character. Write an 8-bit character whose ASCII value is the 1-, 2-, or 3-digit octal number .Ar num . +.It Cm \ex Ns Ar num +Write an 8-bit character whose ASCII value is +the 1- or 2-digit hexadecimal +number +.Ar num . .El .Pp Each format specification is introduced by the percent @@ -383,7 +388,8 @@ and always operates as if were set. .Pp The escape sequences -.Cm \ee +.Cm \ee , +.Cm \ex and .Cm \e' , as well as omitting the leading digit diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 30feac0559a..ecbf4ba5927 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printf.c,v 1.26 2016/11/18 15:53:16 schwarze Exp $ */ +/* $OpenBSD: printf.c,v 1.27 2021/05/07 14:31:27 martijn Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -275,7 +275,7 @@ static int print_escape(const char *str) { const char *start = str; - int value; + int value = 0; int c; str++; @@ -283,7 +283,7 @@ print_escape(const char *str) switch (*str) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - for (c = 3, value = 0; c-- && isodigit(*str); str++) { + for (c = 3; c-- && isodigit(*str); str++) { value <<= 3; value += octtobin(*str); } @@ -293,14 +293,10 @@ print_escape(const char *str) case 'x': str++; - for (value = 0; isxdigit((unsigned char)*str); str++) { + for (c = 2; c-- && isxdigit((unsigned char)*str); str++) { value <<= 4; value += hextobin(*str); } - if (value > UCHAR_MAX) { - warnx ("escape sequence out of range for character"); - rval = 1; - } putchar (value); return str - start - 1; /* NOTREACHED */ |