summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2008-08-02 06:02:02 +0000
committerdas <das@FreeBSD.org>2008-08-02 06:02:02 +0000
commit6781fcee0fd409a644e5fc8f8fe7edcd82c1819f (patch)
treefe4aab46b517b4e83deb6caaa41011dc2ad672bc /usr.bin
parentaffd78d50ba8b1771f24880fb9c08b8cb7efdaff (diff)
downloadFreeBSD-src-6781fcee0fd409a644e5fc8f8fe7edcd82c1819f.zip
FreeBSD-src-6781fcee0fd409a644e5fc8f8fe7edcd82c1819f.tar.gz
POSIX says that octal escapes have the format \ddd in the format string,
but \0ddd in a %b argument, with a length restriction of 3 octal digits in either case. This seems silly, but it needs to be right so it's possible to write an octal escape followed by an ordinary digit. Solaris printf(1) and GNU printf(1) also behave this way. Example: "printf '\0752'" now produces "=2" instead of garbage.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/printf/printf.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index e86394d..5e7a935 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -408,7 +408,8 @@ escape(char *fmt, int percent, size_t *len)
/* octal constant */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
- for (c = *fmt == '0' ? 4 : 3, value = 0;
+ c = (!percent && *fmt == '0') ? 4 : 3;
+ for (value = 0;
c-- && *fmt >= '0' && *fmt <= '7'; ++fmt) {
value <<= 3;
value += *fmt - '0';
OpenPOWER on IntegriCloud