summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-10-21 20:49:50 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-11-11 20:15:22 -0800
commit3f87a8b0b86de83ea8944a53de82caf254a9988a (patch)
tree71faa67bac2a0e47e2d08449851a7c165eb2940f /src
parent613faa245437bb948b4c86ea6c7fbb716e38f0bf (diff)
Use * precision notation instead of computing sprintf format strings
Allows gcc to check format strings instead of just warning about them Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'src')
-rw-r--r--src/util/fontxlfd.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/util/fontxlfd.c b/src/util/fontxlfd.c
index 18046e9..974128e 100644
--- a/src/util/fontxlfd.c
+++ b/src/util/fontxlfd.c
@@ -116,7 +116,6 @@ readreal(char *ptr, double *result)
static char *
xlfd_double_to_text(double value, char *buffer, int space_required)
{
- char formatbuf[40];
register char *p1;
int ndigits, exponent;
@@ -132,14 +131,12 @@ xlfd_double_to_text(double value, char *buffer, int space_required)
minus = locale->negative_sign;
}
#endif
- /* Compute a format to use to render the number */
- sprintf(formatbuf, "%%.%dle", XLFD_NDIGITS);
if (space_required)
*buffer++ = ' ';
/* Render the number using printf's idea of formatting */
- sprintf(buffer, formatbuf, value);
+ sprintf(buffer, "%.*le", XLFD_NDIGITS, value);
/* Find and read the exponent value */
for (p1 = buffer + strlen(buffer);
@@ -156,16 +153,14 @@ xlfd_double_to_text(double value, char *buffer, int space_required)
if (exponent >= XLFD_NDIGITS || ndigits - exponent > XLFD_NDIGITS + 1)
{
/* Scientific */
- sprintf(formatbuf, "%%.%dle", ndigits - 1);
- sprintf(buffer, formatbuf, value);
+ sprintf(buffer, "%.*le", ndigits - 1, value);
}
else
{
/* Fixed */
ndigits -= exponent + 1;
if (ndigits < 0) ndigits = 0;
- sprintf(formatbuf, "%%.%dlf", ndigits);
- sprintf(buffer, formatbuf, value);
+ sprintf(buffer, "%.*lf", ndigits, value);
if (exponent < 0)
{
p1 = buffer;
@@ -265,10 +260,9 @@ xlfd_round_double(double x)
* If not IEEE 754: Let printf() do it for you.
*/
- char formatbuf[40], buffer[40];
+ char buffer[40];
- sprintf(formatbuf, "%%.%dlg", XLFD_NDIGITS);
- sprintf(buffer, formatbuf, x);
+ sprintf(buffer, "%.*lg", XLFD_NDIGITS, x);
return atof(buffer);
}
}