here's a patch that fixes this problem

$ printf "<%3s><%3b>"
<   ><>


---
xoxo iza
From c5ffd55ffa9224dd7919a4d09b27a11308d2152e Mon Sep 17 00:00:00 2001
From: izabera <izaber...@gmail.com>
Date: Sat, 24 Sep 2016 02:01:16 +0200
Subject: [PATCH] fix printf %b without an argument

old behavior:
$ printf "<%3s><%3b>"
<   ><>

removed bogus check on xp returned by bexpand
printstr must not return immediately if the string is null
---
 builtins/printf.def | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/builtins/printf.def b/builtins/printf.def
index d39a6d3..1037b5c 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -543,22 +543,19 @@ printf_builtin (list)
 		ch = rlen = r = 0;
 		xp = bexpand (p, strlen (p), &ch, &rlen);
 
-		if (xp)
+		/* Have to use printstr because of possible NUL bytes
+		   in XP -- printf does not handle that well. */
+		r = printstr (start, xp, rlen, fieldwidth, precision);
+		if (r < 0)
 		  {
-		    /* Have to use printstr because of possible NUL bytes
-		       in XP -- printf does not handle that well. */
-		    r = printstr (start, xp, rlen, fieldwidth, precision);
-		    if (r < 0)
+		    if (ferror (stdout) == 0)
 		      {
-			if (ferror (stdout) == 0)
-			  {
-		            sh_wrerror ();
-			    clearerr (stdout);
-			  }
-		        retval = EXECUTION_FAILURE;
+			sh_wrerror ();
+			clearerr (stdout);
 		      }
-		    free (xp);
+		    retval = EXECUTION_FAILURE;
 		  }
+		free (xp);
 
 		if (ch || r < 0)
 		  PRETURN (retval);
@@ -711,8 +708,7 @@ printstr (fmt, string, len, fieldwidth, precision)
   int fw, pr;			/* fieldwidth and precision */
   intmax_t mfw, mpr;
 
-  if (string == 0 || len == 0)
-    return 0;
+  if (string == 0) string = "";
 
 #if 0
   s = fmt;
-- 
2.10.0

Reply via email to