summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-07-12 15:19:30 +0000
committerpfg <pfg@FreeBSD.org>2014-07-12 15:19:30 +0000
commitcbbccecbf4deb159c344ae31ccd4ee848b0e550e (patch)
treef5acf265389bded8452bd43c98e2761189934874 /lib
parent16670f204520ea21385b04e0f28b3b8b810c1460 (diff)
downloadFreeBSD-src-cbbccecbf4deb159c344ae31ccd4ee848b0e550e.zip
FreeBSD-src-cbbccecbf4deb159c344ae31ccd4ee848b0e550e.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/strfmon.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index b82797d..689c78b 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -526,7 +526,6 @@ __format_grouped_double(double value, int *flags,
char *rslt;
char *avalue;
int avalue_size;
- char fmt[32];
size_t bufsize;
char *bufend;
@@ -567,14 +566,13 @@ __format_grouped_double(double value, int *flags,
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);
OpenPOWER on IntegriCloud