summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-26 11:55:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-01-26 11:58:08 +0100
commitddc5aa7cd3121300f2ba6e68cb038258a616d4e4 (patch)
tree63585f32e5334f6e7ea9f4693e94d740744e5482 /lib.c
parent58e1da9b7dd69af0f32fb2a70c1808dce8c51733 (diff)
vm: fix NaN strict equality tests
A performance shortcut in `ucv_is_equal()` incorrectly led to `NaN === NaN` being true. Fix the issue by only comparing pointers when the involved types are not doubles. Due to fixing `NaN !== NaN`, the `uniq()` function now requires a special case to treat multiple NaNs equal for the sake of generating an array of unique values. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 9d7b26a..7b0c9ca 100644
--- a/lib.c
+++ b/lib.c
@@ -2921,6 +2921,11 @@ uc_uniq_ucv_equal(const void *k1, const void *k2)
if (!ucv_is_scalar(uv1) && !ucv_is_scalar(uv2))
return (uv1 == uv2);
+ /* for the sake of array item uniqueness, treat two NaNs as equal */
+ if (ucv_type(uv1) == UC_DOUBLE && ucv_type(uv2) == UC_DOUBLE &&
+ isnan(ucv_double_get(uv1)) && isnan(ucv_double_get(uv2)))
+ return true;
+
return ucv_is_equal(uv1, uv2);
}