From c357663f0a140dbd51b52c07b5175b2a9e3e38d4 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 20 Mar 2019 22:56:33 -0400 Subject: [PATCH] Issue #310 - Fix type checking for member/assoc --- CHANGELOG.md | 5 +++++ runtime.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f41e36f4..f905de73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,13 @@ Features +- Speed up `case` expressions by using nested `if` expressions instead of the `memv` primitive to evaluate conditions with more than one constant. The nested expressions have better cache locality and also avoid any additional object allocation or initialization. - Allow passing the `'bin` symbol to `Cyc-installation-dir` to return the location of the installation directory for binaries. +Bug Fixes + +- Prevent the possibility of a segmentation fault when passing am improper list to the `member` and `assoc` family of functions. + ## 0.9.10 - March 5, 2019 Features diff --git a/runtime.c b/runtime.c index 5af65d43..7678fba6 100644 --- a/runtime.c +++ b/runtime.c @@ -1231,8 +1231,8 @@ object Cyc_write_u8(void *data, object c, object port) /* Fast versions of member and assoc */ object memberp(void *data, object x, list l) { - Cyc_check_pair_or_null(data, l); for (; l != NULL; l = cdr(l)) { + Cyc_check_pair_or_null(data, l); if (boolean_f != equalp(x, car(l))) return l; } @@ -1241,8 +1241,8 @@ object memberp(void *data, object x, list l) object memqp(void *data, object x, list l) { - Cyc_check_pair_or_null(data, l); for (; l != NULL; l = cdr(l)) { + Cyc_check_pair_or_null(data, l); if ((x == car(l))) return l; } @@ -1254,6 +1254,7 @@ list assq(void *data, object x, list l) if ((l == NULL) || is_value_type(l) || type_of(l) != pair_tag) return boolean_f; for (; (l != NULL); l = cdr(l)) { + Cyc_check_pair(data, l); list la = car(l); Cyc_check_pair(data, la); if ((x == car(la))) @@ -1267,6 +1268,7 @@ list assoc(void *data, object x, list l) if ((l == NULL) || is_value_type(l) || type_of(l) != pair_tag) return boolean_f; for (; (l != NULL); l = cdr(l)) { + Cyc_check_pair(data, l); list la = car(l); Cyc_check_pair(data, la); if (boolean_f != equalp(x, car(la)))