-.\" $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.
.\"
.\" 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
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
were set.
.Pp
The escape sequences
-.Cm \ee
+.Cm \ee ,
+.Cm \ex
and
.Cm \e' ,
as well as omitting the leading digit
-/* $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.
print_escape(const char *str)
{
const char *start = str;
- int value;
+ int value = 0;
int c;
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);
}
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 */