From 5bb09860276ee5a209abe526c922b838c01af549 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 27 Jan 2012 13:56:14 -0800 Subject: * hash.c (hash_begin): Missing type check added, otherwise passing in an object that is not a hash results in corruption or crashing behavior. * lib.c (class_check): Improved to a one-step check with a clear message. --- ChangeLog | 9 +++++++++ hash.c | 5 ++++- lib.c | 5 ++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24f4f8d2..1f64592f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-01-27 Kaz Kylheku + + * hash.c (hash_begin): Missing type check added, otherwise + passing in an object that is not a hash results in corruption + or crashing behavior. + + * lib.c (class_check): Improved to a one-step check with a clear + message. + 2012-01-26 Kaz Kylheku Version 55 diff --git a/hash.c b/hash.c index e03664cd..e8f5bb1b 100644 --- a/hash.c +++ b/hash.c @@ -389,7 +389,10 @@ static struct cobj_ops hash_iter_ops = { val hash_begin(val hash) { val hi_obj; - struct hash_iter *hi = (struct hash_iter *) chk_malloc(sizeof *hi); + struct hash_iter *hi; + class_check (hash, hash_s); + + hi = (struct hash_iter *) chk_malloc(sizeof *hi); hi->hash = nil; hi->chain = -1; hi->cons = nil; diff --git a/lib.c b/lib.c index 881d2c0c..0aedac3f 100644 --- a/lib.c +++ b/lib.c @@ -169,9 +169,8 @@ val type_check3(val obj, int t1, int t2, int t3) val class_check(val cobj, val class_sym) { - type_check (cobj, COBJ); - type_assert (cobj->co.cls == class_sym, (lit("~a is not a cobj of class ~a"), - cobj, class_sym)); + type_assert (cobj && cobj->t.type == COBJ && cobj->co.cls == class_sym, + (lit("~a is not of type ~a"), cobj, class_sym, nao)); return t; } -- cgit v1.2.3