From db7d1ed2b11cf17c3fc110eeede13ceba17fef33 Mon Sep 17 00:00:00 2001 From: spew Date: Thu, 18 Aug 2016 08:52:58 -0500 Subject: [PATCH] fix awk format printing bugs (thanks aiju) --- sys/src/cmd/awk/run.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/awk/run.c b/sys/src/cmd/awk/run.c index 416d3a8c7..6627f661c 100644 --- a/sys/src/cmd/awk/run.c +++ b/sys/src/cmd/awk/run.c @@ -895,18 +895,21 @@ int format(char **pbuf, int *pbufsize, char *s, Node *a) /* printf-like conversi case 'd': case 'i': flag = 2; if(*(s-1) == 'l') break; - *(t-1) = 'l'; + t[-1] = 'l'; *t = 'd'; *++t = '\0'; break; case 'u': flag = *(s-1) == 'l' ? 2 : 3; - *t++ = 'u'; + t[-1] = 'u'; *t++ = 'd'; *t = '\0'; break; case 'o': case 'x': case 'X': flag = *(s-1) == 'l' ? 2 : 3; + t[-1] = 'u'; + *t++ = *s; + *t = '\0'; break; case 's': flag = 4; @@ -939,7 +942,7 @@ int format(char **pbuf, int *pbufsize, char *s, Node *a) /* printf-like conversi break; case 1: sprint(p, fmt, getfval(x)); break; case 2: sprint(p, fmt, (long) getfval(x)); break; - case 3: sprint(p, fmt, (int) getfval(x)); break; + case 3: sprint(p, fmt, (int) getfval(x)); break; case 4: t = getsval(x); n = strlen(t);