aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/node.c4
-rw-r--r--tests/serd_test.c7
3 files changed, 11 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index de2d0894..174af7b0 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,12 @@
serd (0.18.1) unstable;
+ * Fix crash when serd_node_new_decimal is called with infinity or NaN
* Fix crash when resolving against non-standard base URIs
* Fix bug that caused "a" abbreviation in non-predicate position
* Disable timestamps in HTML documentation for reproducible build
* Fix clashing symbol "error" in amalgamation build
- -- David Robillard <d@drobilla.net> Thu, 20 Dec 2012 16:27:10 -0500
+ -- David Robillard <d@drobilla.net> Fri, 21 Dec 2012 13:26:05 -0500
serd (0.18.0) stable;
diff --git a/src/node.c b/src/node.c
index 7f6e9863..061903bc 100644
--- a/src/node.c
+++ b/src/node.c
@@ -211,6 +211,10 @@ SERD_API
SerdNode
serd_node_new_decimal(double d, unsigned frac_digits)
{
+ if (isnan(d) || isinf(d)) {
+ return SERD_NODE_NULL;
+ }
+
const double abs_d = fabs(d);
const unsigned int_digits = (unsigned)fmax(1.0, ceil(log10(abs_d + 1)));
char* buf = (char*)calloc(int_digits + frac_digits + 3, 1);
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 7ce2aa55..f53e3494 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -114,15 +114,18 @@ main(void)
// Test serd_node_new_decimal
const double dbl_test_nums[] = {
- 0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001
+ 0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001, NAN, INFINITY
};
const char* dbl_test_strs[] = {
- "0.0", "9.0", "10.0", "0.01", "2.05", "-16.00001", "5.00000001", "0.0"
+ "0.0", "9.0", "10.0", "0.01", "2.05", "-16.00001", "5.00000001", "0.0", NULL, NULL
};
for (unsigned i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) {
SerdNode node = serd_node_new_decimal(dbl_test_nums[i], 8);
+ if (node.buf == dbl_test_strs[i]) {
+ continue;
+ }
if (strcmp((const char*)node.buf, (const char*)dbl_test_strs[i])) {
return failure("Serialised `%s' != %s\n",
node.buf, dbl_test_strs[i]);