summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-06-20 22:46:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-06-20 22:46:18 -0700
commit2619181c7f4139af56f2fce340d2b0046b12d552 (patch)
treec6b649f965be4a59ca356826f3985752f8e3ee54 /ffi.c
parentf34284f052caacc7e0873d8ea333d372e8e10125 (diff)
downloadtxr-2619181c7f4139af56f2fce340d2b0046b12d552.tar.gz
txr-2619181c7f4139af56f2fce340d2b0046b12d552.tar.bz2
txr-2619181c7f4139af56f2fce340d2b0046b12d552.zip
ffi: fix broken float put.
* ffi.c (ffi_float_put): Fix silly range check: FLT_MIN and FLT_MAX are, of course, both positive. Also, fix num being used as an argument in the error diagnostic. It's the address of a C function, not an object.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ffi.c b/ffi.c
index 51d938b9..de71d9a8 100644
--- a/ffi.c
+++ b/ffi.c
@@ -27,6 +27,7 @@
#include <limits.h>
#include <float.h>
+#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -684,8 +685,11 @@ static void ffi_float_put(struct txr_ffi_type *tft, val n, mem_t *dst, val self)
break;
}
- if (v > FLT_MAX || v < FLT_MIN)
- uw_throwf(error_s, lit("~a: ~s is out of float range"), self, num, nao);
+ {
+ double pv = fabs(v);
+ if (pv > FLT_MAX || (pv != 0.0 && pv < FLT_MIN))
+ uw_throwf(error_s, lit("~a: ~s is out of float range"), self, n, nao);
+ }
align_sw_put(double, dst, *coerce(float *, dst) = v);
}