Merge branch 'segfault_on_top_level_super_with_no_args' of git://github.com/zeckalpha/wren into zeckalpha-segfault_on_top_level_super_with_no_args

This commit is contained in:
Bob Nystrom
2015-01-11 19:42:26 -08:00
2 changed files with 13 additions and 2 deletions

View File

@ -1852,8 +1852,16 @@ static void super_(Compiler* compiler, bool allowAssignment)
{
// No explicit name, so use the name of the enclosing method.
char name[MAX_METHOD_SIGNATURE];
int length = enclosingClass->methodLength;
strncpy(name, enclosingClass->methodName, length);
int length;
if (enclosingClass != NULL) {
length = enclosingClass->methodLength;
strncpy(name, enclosingClass->methodName, length);
} else {
// The compiler errored since super is called outside a method.
// We want to continue, but we cannot generate valid bytecode.
length = 0;
strncpy(name, "", length);
}
// Call the superclass method with the same name.
methodCall(compiler, CODE_SUPER_0, name, length);

View File

@ -1 +1,4 @@
super.foo // expect error
super // expect error
super.foo("bar") // expect error
super("foo") // expect error