aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1993-07-22 08:34:30 +0000
committerRichard M. Stallman1993-07-22 08:34:30 +0000
commit322890c475dee6339bf8d53564ff87a8a0e2d0c3 (patch)
tree67925ddedcd860dab0e53bede84ed47aff6dea76 /src
parentb8e4857c8119527360091b3f8274a7b24c08d686 (diff)
downloademacs-322890c475dee6339bf8d53564ff87a8a0e2d0c3.tar.gz
emacs-322890c475dee6339bf8d53564ff87a8a0e2d0c3.zip
(float_to_string): Don't use uninitialized pointer `cp'.
Set width to -1 at lose: and other places. Default to .17g, not .20g.
Diffstat (limited to 'src')
-rw-r--r--src/print.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/print.c b/src/print.c
index 0d909432cf6..3447f786d2d 100644
--- a/src/print.c
+++ b/src/print.c
@@ -611,12 +611,15 @@ float_to_string (buf, data)
611 double data; 611 double data;
612{ 612{
613 unsigned char *cp; 613 unsigned char *cp;
614 int width = -1; 614 int width;
615 615
616 if (NILP (Vfloat_output_format) 616 if (NILP (Vfloat_output_format)
617 || XTYPE (Vfloat_output_format) != Lisp_String) 617 || XTYPE (Vfloat_output_format) != Lisp_String)
618 lose: 618 lose:
619 sprintf (buf, "%.20g", data); 619 {
620 sprintf (buf, "%.17g", data);
621 width = -1;
622 }
620 else /* oink oink */ 623 else /* oink oink */
621 { 624 {
622 /* Check that the spec we have is fully valid. 625 /* Check that the spec we have is fully valid.
@@ -632,6 +635,7 @@ float_to_string (buf, data)
632 cp += 2; 635 cp += 2;
633 636
634 /* Check the width specification. */ 637 /* Check the width specification. */
638 width = -1;
635 if ('0' <= *cp && *cp <= '9') 639 if ('0' <= *cp && *cp <= '9')
636 for (width = 0; (*cp >= '0' && *cp <= '9'); cp++) 640 for (width = 0; (*cp >= '0' && *cp <= '9'); cp++)
637 width = (width * 10) + (*cp - '0'); 641 width = (width * 10) + (*cp - '0');
@@ -654,9 +658,9 @@ float_to_string (buf, data)
654 658
655 /* Make sure there is a decimal point with digit after, or an 659 /* Make sure there is a decimal point with digit after, or an
656 exponent, so that the value is readable as a float. But don't do 660 exponent, so that the value is readable as a float. But don't do
657 this with "%.0f"; it's legal for that not to produce a decimal 661 this with "%.0f"; it's valid for that not to produce a decimal
658 point. */ 662 point. Note that width can be 0 only for %.0f. */
659 if (*cp != 'f' || width != 0) 663 if (width != 0)
660 { 664 {
661 for (cp = buf; *cp; cp++) 665 for (cp = buf; *cp; cp++)
662 if ((*cp < '0' || *cp > '9') && *cp != '-') 666 if ((*cp < '0' || *cp > '9') && *cp != '-')
@@ -1038,7 +1042,7 @@ Use `g' to choose the shorter of those two formats for the number at hand.\n\
1038The precision in any of these cases is the number of digits following\n\ 1042The precision in any of these cases is the number of digits following\n\
1039the decimal point. With `f', a precision of 0 means to omit the\n\ 1043the decimal point. With `f', a precision of 0 means to omit the\n\
1040decimal point. 0 is not allowed with `e' or `g'.\n\n\ 1044decimal point. 0 is not allowed with `e' or `g'.\n\n\
1041A value of nil means to use `%.20g'."); 1045A value of nil means to use `%.17g'.");
1042 Vfloat_output_format = Qnil; 1046 Vfloat_output_format = Qnil;
1043 Qfloat_output_format = intern ("float-output-format"); 1047 Qfloat_output_format = intern ("float-output-format");
1044 staticpro (&Qfloat_output_format); 1048 staticpro (&Qfloat_output_format);