From b53f80bc65b8cb7d382f4c16b6218ccfcb579ef5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 13 Nov 2009 17:08:35 -0800 Subject: * lib.c (symbolp): Bugfix: function crashed on NUM argument. (lazy_str): Fix for gc correctness: object from make_obj must be completely intialized before any gc-triggering operation is invoked, otherwise the garbage collector will be traversing an object whose fields contain old garbage. (lazy_str_force_upto): Off-by-one error. To force the object up to index position N, means forcing up to length N+1. This bug can make it look like a lazy string is much shorter than it really is. --- ChangeLog | 12 ++++++++++++ lib.c | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb277664..c823056f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-11-13 Kaz Kylheku + + * lib.c (symbolp): Bugfix: function crashed on NUM argument. + (lazy_str): Fix for gc correctness: object from make_obj must be + completely intialized before any gc-triggering operation is invoked, + otherwise the garbage collector will be traversing an object + whose fields contain old garbage. + (lazy_str_force_upto): Off-by-one error. To force the object + up to index position N, means forcing up to length N+1. + This bug can make it look like a lazy string is much shorter + than it really is. + 2009-11-13 Kaz Kylheku Allow -c scripts to not have a trailing newline. diff --git a/lib.c b/lib.c index 280f6284..10c4f972 100644 --- a/lib.c +++ b/lib.c @@ -1043,7 +1043,7 @@ obj_t *intern(obj_t *str) obj_t *symbolp(obj_t *sym) { - return (sym == nil || sym->s.type == SYM) ? t : nil; + return (sym == nil || (is_ptr(sym) && sym->s.type == SYM)) ? t : nil; } obj_t *func_f0(obj_t *env, obj_t *(*fun)(obj_t *)) @@ -1385,6 +1385,7 @@ obj_t *lazy_str(obj_t *lst, obj_t *term, obj_t *limit) { obj_t *obj = make_obj(); obj->ls.type = LSTR; + obj->ls.opts = nil; /* Must init before calling something that can gc! */ term = or2(term, string(L"\n")); @@ -1428,7 +1429,7 @@ obj_t *lazy_str_force_upto(obj_t *lstr, obj_t *index) type_check(lstr, LSTR); lim = cdr(lstr->ls.opts); - while (gt(index, length_str(lstr->ls.prefix)) && lstr->ls.list && + while (ge(index, length_str(lstr->ls.prefix)) && lstr->ls.list && or2(nullp(lim),gt(lim,zero))) { obj_t *next = pop(&lstr->ls.list); -- cgit v1.2.3