From e7fc06910b2e4422babfa281aafd66adbd792c9a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 29 Oct 2014 20:42:24 -0700 Subject: [PATCH] Fix a crash when properties have setters but not getters. --- sourcepawn/compiler/sc1.cpp | 3 +-- sourcepawn/compiler/sc3.cpp | 2 +- sourcepawn/compiler/sctracker.h | 13 +++++++++++++ sourcepawn/compiler/tests/ok-setter-no-getter.sp | 12 ++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 sourcepawn/compiler/tests/ok-setter-no-getter.sp diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index d1116997..cb1a7520 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -3686,8 +3686,7 @@ int parse_property_accessor(const typeinfo_t *type, methodmap_t *map, methodmap_ // Must have one extra argument taking the return type. arginfo *arg = &target->dim.arglist[1]; - if (arg->ident == 0 || - arg->ident != iVARIABLE || + if (arg->ident != iVARIABLE || arg->hasdefault || arg->numtags != 1 || arg->tags[0] != type->tag) diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp index 965eb0c0..1e1fe9e6 100644 --- a/sourcepawn/compiler/sc3.cpp +++ b/sourcepawn/compiler/sc3.cpp @@ -2174,7 +2174,7 @@ restart: rvalue(lval1); clear_value(lval1); lval1->ident = iACCESSOR; - lval1->tag = method->getter->tag; + lval1->tag = method->property_tag(); lval1->accessor = method; lvalue = TRUE; goto restart; diff --git a/sourcepawn/compiler/sctracker.h b/sourcepawn/compiler/sctracker.h index a9ff552c..997a99dc 100644 --- a/sourcepawn/compiler/sctracker.h +++ b/sourcepawn/compiler/sctracker.h @@ -85,6 +85,19 @@ typedef struct methodmap_method_s symbol *target; symbol *getter; symbol *setter; + + int property_tag() const { + assert(getter || setter); + if (getter) + return getter->tag; + arginfo *thisp = &setter->dim.arglist[0]; + if (thisp->ident == 0) + return pc_tag_void; + arginfo *valp = &setter->dim.arglist[1]; + if (valp->ident != iVARIABLE || valp->numtags != 1) + return pc_tag_void; + return valp->tags[0]; + } } methodmap_method_t; typedef struct methodmap_s diff --git a/sourcepawn/compiler/tests/ok-setter-no-getter.sp b/sourcepawn/compiler/tests/ok-setter-no-getter.sp new file mode 100644 index 00000000..86c28fd6 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-setter-no-getter.sp @@ -0,0 +1,12 @@ +methodmap Crab +{ + property int X { + public native set(int value); + } +} + +public main() +{ + Crab crab; + crab.X = 12; +}