# HG changeset patch # User Michael Busby # Date 1346817802 25200 # Node ID b98a56a533d0d519d801df8c684944465484b813 # Parent 5f3c91fa6058b40d08fbb5a4f417fdad43255929 Empty structs throw a compiler error instead of crashing the vm. (bug 5475, r=dvander). diff -r 5f3c91fa6058 -r b98a56a533d0 src/Messages.tbl --- a/src/Messages.tbl Thu Sep 13 23:58:22 2012 -0700 +++ b/src/Messages.tbl Tue Sep 04 21:03:22 2012 -0700 @@ -73,4 +73,4 @@ MSG(CaseMustBeConstant, SyntaxError, "case expression must be a constant") MSG(CaseHasSameValue, SyntaxError, "case value appears twice in the same switch") MSG(CaseMustBeInteger, SyntaxError, "switch may only operate on integer values") - +MSG(StructCantBeEmpty, SyntaxError, "struct cannot be declared without any fields") diff -r 5f3c91fa6058 -r b98a56a533d0 src/Parser.cpp --- a/src/Parser.cpp Thu Sep 13 23:58:22 2012 -0700 +++ b/src/Parser.cpp Tue Sep 04 21:03:22 2012 -0700 @@ -1126,6 +1126,11 @@ if (!expect(TOK_RBRACE)) return NULL; + if (fields->empty()) { + cc_.reportError(pos, Message_StructCantBeEmpty); + return NULL; + } + return new (pool_) StructureStatement(pos, type, fields); }