zsh-workers
 help / color / mirror / code / Atom feed
* [bug] Incorrect output from printf '{%-5.s}' 123456789
@ 2016-04-21 22:21 Ryan Wilson
  2016-04-22  1:16 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Wilson @ 2016-04-21 22:21 UTC (permalink / raw)
  To: zsh-workers

It appears that zsh doesn't handle the precision specifier for %s correctly in
the printf builtin:

% builtin printf '{%-5.s}' 123456789
{123456789}
% command printf '{%-5.s}' 123456789
{     }
% bash -c "builtin printf '{%-5.s}' 123456789"
{     }
% dash -c "printf '{%-5.s}' 123456789"
{     }

man 3 printf says that for %s "if the precision is given as just '.', the
precision is taken to be zero.". Since the precision specifier for %s gives the
maximum number of characters to print, with a precision of zero the effect of
%-5.s should be to right-pad the empty string with 5 spaces. But instead zsh
ignores this and prints the full string.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug] Incorrect output from printf '{%-5.s}' 123456789
  2016-04-21 22:21 [bug] Incorrect output from printf '{%-5.s}' 123456789 Ryan Wilson
@ 2016-04-22  1:16 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2016-04-22  1:16 UTC (permalink / raw)
  To: Ryan Wilson, zsh-workers@zsh.org 

On Apr 21,  5:21pm, Ryan Wilson wrote:
} Subject: [bug] Incorrect output from printf '{%-5.s}' 123456789
}
} It appears that zsh doesn't handle the precision specifier for %s
} correctly in the printf builtin:
} 
} % builtin printf '{%-5.s}' 123456789
} {123456789}

Well, hrm.

diff --git a/Src/builtin.c b/Src/builtin.c
index 4c8fbcd..ad01ad4 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4736,7 +4736,8 @@ bin_print(char *name, char **args, Options ops, int func)
 		} else if (idigit(*c)) {
 		    prec = strtoul(c, &endptr, 0);
 		    c = endptr;
-		}
+		} else
+		    prec = 0;
 		if (prec >= 0) *d++ = '.', *d++ = '*';
 	    }
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-22  1:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-21 22:21 [bug] Incorrect output from printf '{%-5.s}' 123456789 Ryan Wilson
2016-04-22  1:16 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).