Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Aug 2018 15:25:01 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337458 - head/usr.bin/printf
Message-ID:  <201808081525.w78FP1TS035564@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Wed Aug  8 15:25:01 2018
New Revision: 337458
URL: https://svnweb.freebsd.org/changeset/base/337458

Log:
  Fix printf(1) ignores width and precision in %b format.
  
  The precision with the conversion specifier b is specified by POSIX: see
  point 7 in the reference documentation.
  
  This corrects previous wrong log in r337440.
  
  Reference: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
  
  PR:	229641
  Reported by:	Rudolf Cejka
  Submitted by:	Garrett D'Amore (illumos)
  MFC after:	1 week

Modified:
  head/usr.bin/printf/printf.c

Modified: head/usr.bin/printf/printf.c
==============================================================================
--- head/usr.bin/printf/printf.c	Wed Aug  8 15:12:32 2018	(r337457)
+++ head/usr.bin/printf/printf.c	Wed Aug  8 15:25:01 2018	(r337458)
@@ -1,6 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
  *
+ * Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 1989, 1993
@@ -375,16 +376,19 @@ printf_doformat(char *fmt, int *rval)
 		char *p;
 		int getout;
 
-		p = strdup(getstr());
-		if (p == NULL) {
+		/* Convert "b" to "s" for output. */
+		start[strlen(start) - 1] = 's';
+		if ((p = strdup(getstr())) == NULL) {
 			warnx("%s", strerror(ENOMEM));
 			return (NULL);
 		}
 		getout = escape(p, 0, &len);
-		fputs(p, stdout);
+		PF(start, p);
+		/* Restore format for next loop. */
+
 		free(p);
 		if (getout)
-			return (end_fmt);
+			exit(*rval);
 		break;
 	}
 	case 'c': {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808081525.w78FP1TS035564>