diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-03-22 10:18:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-03-22 10:18:33 -0700 |
commit | 6254e4fa987437b1d785cae66122d707c886e144 (patch) | |
tree | 45ecf360d0748a1f33a18f93d6dde199cde4b497 /stream.c | |
parent | d4a331511ffa45f41a0a619649e366905e406037 (diff) | |
download | txr-6254e4fa987437b1d785cae66122d707c886e144.tar.gz txr-6254e4fa987437b1d785cae66122d707c886e144.tar.bz2 txr-6254e4fa987437b1d785cae66122d707c886e144.zip |
* arith.c (int_flo): If sprintf produces something
that doesn't begin with a digit, it's most likely NaN or Inf.
We can turn that into an exception.
* stream.c (vformat): If sprintf produces a non-number,
turn it into the printed representation #<bad-float>.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -32,6 +32,7 @@ #include <assert.h> #include <setjmp.h> #include <errno.h> +#include <ctype.h> #include <wchar.h> #include <unistd.h> #include "config.h" @@ -1147,6 +1148,12 @@ val vformat(val stream, val fmtstr, va_list vl) sprintf(num_buf, "%.*e", precision, n); else sprintf(num_buf, "%.*f", precision, n); + if (!isdigit(num_buf[0])) { + if (!vformat_str(stream, lit("#<bad-float>"), + width, left, precision)) + return nil; + continue; + } precision = 0; goto output_num; } @@ -1170,6 +1177,13 @@ val vformat(val stream, val fmtstr, va_list vl) case FLNUM: sprintf(num_buf, "%g", obj->fl.n); + if (!isdigit(num_buf[0])) { + if (!vformat_str(stream, lit("#<bad-float>"), + width, left, precision)) + return nil; + continue; + } + if (!precision) { if (!strpbrk(num_buf, "e.")) strcat(num_buf, ".0"); |