[kaffe] libraries/clib/native/{Double,Float}.c issues

Eric Anholt eta at lclark.edu
Thu Oct 21 00:57:47 PDT 2004

So, first thing I ran into when trying to run some trivial classes was
Null Pointer Exceptions (actually segfaults) in Double.c.  First, using
sprintf led to walking past the end of the buffer when there were very
large precision values.  Making those into snprintfs left issues,
apparently with the very large precision values supplied to strtod, so I
clamped the maximum precision.  That got me farther, except for
NumberFormatExceptions.  These were due to printf("%.*f", 0, 0.0)
producing "0" instead of "0.0" as the code seemed to expect.  Ending the
trailing-0-stripping loop when we were near the start of the string
seemed to clear that one up.  As far as whether this behavior is to be
expected, from our manpage:

     fF      The double argument is rounded and converted to decimal notation
             in the style [-]ddd.ddd, where the number of digits after the
             decimal-point character is equal to the precision specification.
             If the precision is missing, it is taken as 6; if the precision
             is explicitly zero, no decimal-point character appears.  If a
             decimal point appears, at least one digit appears before it.
     Subject to the caveats noted in the BUGS section below, the fprintf(),
     printf(), sprintf(), vprintf(), vfprintf(), and vsprintf() functions con-
     form to ANSI X3.159-1989 (``ANSI C89'') and ISO/IEC 9899:1999
     (``ISO C99'').  With the same reservation, the snprintf() and vsnprintf()
     functions conform to ISO/IEC 9899:1999 (``ISO C99'').

I tested on a linux system, and got the same result from printf("%.*f",
0, 0.0).

Attached is a patch for all of my Double.c fixes, plus those fixes
ported to Float.c, and use of strtof in Float.c instead of strtod with a
(float) cast.

However, I'm still seeing insanely long times to run simple tests like 
DoublePrint.java.  Not sure what's going on here.

Eric Anholt                                eta at lclark.edu          
http://people.freebsd.org/~anholt/         anholt at FreeBSD.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kaffe-tostring.diff
Type: text/x-patch
Size: 4972 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20041021/d2d1a660/attachment-0002.bin 

More information about the kaffe mailing list