From 15dc1a86cd9e1fd22a46fde1a3632418eb8d9466 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 3 Sep 2014 12:23:15 -0700 Subject: [PATCH] Fixed flatc silently accepting non-scalars as default values. Bug: 17304016 Change-Id: I4873f8ef32fbb2657f15fc53a2c8f767e10f2d96 Tested: on Linux --- src/idl_parser.cpp | 2 ++ tests/test.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 37ff146..9911fab 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -364,6 +364,8 @@ void Parser::ParseField(StructDef &struct_def) { if (token_ == '=') { Next(); + if (!IsScalar(type.base_type)) + Error("default values currently only supported for scalars"); ParseSingleValue(field.value); } diff --git a/tests/test.cpp b/tests/test.cpp index edb971a..03955e3 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -489,6 +489,7 @@ void ErrorTest() { TestError("union X { Y }", "referenced"); TestError("union Z { X } struct X { Y:int; }", "only tables"); TestError("table X { Y:[int]; YLength:int; }", "clash"); + TestError("table X { Y:string = 1; }", "scalar"); } // Additional parser testing not covered elsewhere. -- 2.7.4