Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Ignore the zero padding format modifier with sting values
Matthew Seaman committed 10 years ago
commit 1e310be9349fb2388bb561f10f2080489abe5304
parent 9af2287138a3d9f0622f13b93141a16107b474b1
3 files changed +12 -6
modified docs/pkg_printf.3
@@ -310,6 +310,8 @@ respectively.
Zero padding.
For all integer valued conversions and humanized numbers the converted
value is padded on the left with zeros rather than blanks.
+
For string valued conversions, this has no effect and the converted
+
value is padded on the left with blanks.
.It Cm \-
A negative field width flag;
the converted value is to be left adjusted on the field boundary.
modified libpkg/pkg_printf.c
@@ -1,5 +1,5 @@
/*
-
 * Copyright (c) 2012-2013 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2012-2015 Matthew Seaman <matthew@FreeBSD.org>
 * Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
 * All rights reserved.
 * 
@@ -2084,13 +2084,14 @@ string_val(struct sbuf *sbuf, const char *str, struct percent_esc *p)
{
	char	format[16];

-
	/* The '#' '?' '+' ' ' and '\'' modifiers have no meaning for
-
	   strings */
+
	/* The '#' '?' '+' ' ' '0' and '\'' modifiers have no meaning
+
	   for strings */

	p->flags &= ~(PP_ALTERNATE_FORM1 |
		      PP_ALTERNATE_FORM2 |
		      PP_EXPLICIT_PLUS   |
		      PP_SPACE_FOR_PLUS  |
+
		      PP_ZERO_PAD        |
		      PP_THOUSANDS_SEP);

	if (gen_format(format, sizeof(format), p->flags, "s") == NULL)
modified tests/lib/pkg_printf_test.c
@@ -359,13 +359,16 @@ ATF_TC_BODY(string_val, tc)
		{ "xxy", "xxy  ",  5, PP_LEFT_ALIGN, },
		{ "xxy", "xxy   ", 6, PP_LEFT_ALIGN, },

+
		/* Zero padding a string is non-portable, so ignore 
+
		   that flag when printing string values */
+

		{ "xxz", "xxz",    0, PP_ZERO_PAD, },
		{ "xxz", "xxz",    1, PP_ZERO_PAD, },
		{ "xxz", "xxz",    2, PP_ZERO_PAD, },
		{ "xxz", "xxz",    3, PP_ZERO_PAD, },
-
		{ "xxz", "0xxz",   4, PP_ZERO_PAD, },
-
		{ "xxz", "00xxz",  5, PP_ZERO_PAD, },
-
		{ "xxz", "000xxz", 6, PP_ZERO_PAD, },
+
		{ "xxz", " xxz",   4, PP_ZERO_PAD, },
+
		{ "xxz", "  xxz",  5, PP_ZERO_PAD, },
+
		{ "xxz", "   xxz", 6, PP_ZERO_PAD, },

		/* Seems you can't zero pad on the RHS of a string */