Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jul 2014 15:19:30 +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: r268569 - head/lib/libc/stdlib
Message-ID:  <201407121519.s6CFJUvQ054252@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sat Jul 12 15:19:30 2014
New Revision: 268569
URL: http://svnweb.freebsd.org/changeset/base/268569

Log:
  strfmon: reduce unnecessary snprintf.
  
  No need for the snprintf/asprintf dance; use fixed width formats.
  
  Obtained from:	NetBSD (CVS rev. 1.8)
  MFC after:	1 week

Modified:
  head/lib/libc/stdlib/strfmon.c

Modified: head/lib/libc/stdlib/strfmon.c
==============================================================================
--- head/lib/libc/stdlib/strfmon.c	Sat Jul 12 10:27:30 2014	(r268568)
+++ head/lib/libc/stdlib/strfmon.c	Sat Jul 12 15:19:30 2014	(r268569)
@@ -526,7 +526,6 @@ __format_grouped_double(double value, in
 	char		*rslt;
 	char		*avalue;
 	int		avalue_size;
-	char		fmt[32];
 
 	size_t		bufsize;
 	char		*bufend;
@@ -567,14 +566,13 @@ __format_grouped_double(double value, in
 		left_prec += get_groups(left_prec, grouping);
 
 	/* convert to string */
-	snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1,
-	    right_prec);
-	avalue_size = asprintf(&avalue, fmt, value);
+	avalue_size = asprintf(&avalue, "%*.*f", left_prec + right_prec + 1,
+	    right_prec, value);
 	if (avalue_size < 0)
 		return (NULL);
 
 	/* make sure that we've enough space for result string */
-	bufsize = strlen(avalue)*2+1;
+	bufsize = avalue_size * 2 + 1;
 	rslt = calloc(1, bufsize);
 	if (rslt == NULL) {
 		free(avalue);



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