mirror of
https://github.com/openbsd/src.git
synced 2025-01-04 15:25:38 -08:00
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@
This commit is contained in:
parent
979e698191
commit
d34695b63e
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user