summary refs log tree commit diff
path: root/src/bltin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bltin')
-rw-r--r--src/bltin/printf.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index d1181e3..ebc74ae 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -44,8 +44,7 @@ static int	 conv_escape_str(char *, char **);
 static char	*conv_escape(char *, int *);
 static int	 getchr(void);
 static double	 getdouble(void);
-static intmax_t	 getintmax(void);
-static uintmax_t getuintmax(void);
+static uintmax_t getuintmax(int);
 static char	*getstr(void);
 static char	*mklong(const char *, const char *);
 static void      check_conversion(const char *, const char *);
@@ -179,14 +178,14 @@ pc:
 			/* skip to field width */
 			fmt += strspn(fmt, SKIP1);
 			if (*fmt == '*')
-				*param++ = getintmax();
+				*param++ = getuintmax(1);
 
 			/* skip to possible '.', get following precision */
 			fmt += strspn(fmt, SKIP2);
 			if (*fmt == '.')
 				++fmt;
 			if (*fmt == '*')
-				*param++ = getintmax();
+				*param++ = getuintmax(1);
 
 			fmt += strspn(fmt, SKIP2);
 
@@ -220,18 +219,18 @@ pc:
 			}
 			case 'd':
 			case 'i': {
-				intmax_t p = getintmax();
-				char *f = mklong(start, fmt);
-				PF(f, p);
+				uintmax_t p = getuintmax(1);
+				start = mklong(start, fmt);
+				PF(start, p);
 				break;
 			}
 			case 'o':
 			case 'u':
 			case 'x':
 			case 'X': {
-				uintmax_t p = getuintmax();
-				char *f = mklong(start, fmt);
-				PF(f, p);
+				uintmax_t p = getuintmax(0);
+				start = mklong(start, fmt);
+				PF(start, p);
 				break;
 			}
 			case 'a':
@@ -404,30 +403,8 @@ getstr(void)
 	return val;
 }
 
-static intmax_t
-getintmax(void)
-{
-	intmax_t val = 0;
-	char *cp, *ep;
-
-	cp = *gargv;
-	if (cp == NULL)
-		goto out;
-	gargv++;
-
-	val = (unsigned char) cp[1];
-	if (*cp == '\"' || *cp == '\'')
-		goto out;
-
-	errno = 0;
-	val = strtoimax(cp, &ep, 0);
-	check_conversion(cp, ep);
-out:
-	return val;
-}
-
 static uintmax_t
-getuintmax(void)
+getuintmax(int sign)
 {
 	uintmax_t val = 0;
 	char *cp, *ep;
@@ -442,7 +419,7 @@ getuintmax(void)
 		goto out;
 
 	errno = 0;
-	val = strtoumax(cp, &ep, 0);
+	val = sign ? strtoimax(cp, &ep, 0) : strtoumax(cp, &ep, 0);
 	check_conversion(cp, ep);
 out:
 	return val;