From 927a446bd3e3867df746f3049a28cfd5c6592135 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 9 Jun 2021 12:08:13 +0900 Subject: [PATCH] [qfcc] Ensure type src type is a class If the src type is not a class, there is no inheritance chain to walk. Fixes a segfault when returning self after a syntax error in the following: +(EditStatus *)withRect:(Rect)rect { return [[[self alloc] initWithRect:rect]: } -setCursorMode:(CursorMode)mode { cursorMode = mode; return self; } --- tools/qfcc/source/class.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index ddef199fa..b61be1d26 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -455,7 +455,7 @@ category_implements (category_t *cat, protocol_t *protocol) int obj_types_assignable (const type_t *dst, const type_t *src) { - class_t *dst_class, *src_class; + class_t *dst_class, *src_class = 0; category_t *cat; int dst_is_proto, src_is_proto; protocollist_t *dst_protos = 0, *src_protos = 0; @@ -507,7 +507,9 @@ obj_types_assignable (const type_t *dst, const type_t *src) // check dst is a base class of src dst_class = dst->t.fldptr.type->t.class; - src_class = src->t.fldptr.type->t.class; + if (src->t.fldptr.type->meta == ty_class) { + src_class = src->t.fldptr.type->t.class; + } //printf ("%s %s\n", dst_class->name, src_class->name); while (dst_class != src_class && src_class) { src_class = src_class->super_class;