Browse Source

Merge pull request #44452 from RandomShaper/fix_crash_parsing_ref

Fix crash parsing a serialized Reference
Rémi Verschelde 4 years ago
parent
commit
f47ef030d0
1 changed files with 3 additions and 6 deletions
  1. 3 6
      core/variant/variant_parser.cpp

+ 3 - 6
core/variant/variant_parser.cpp

@@ -743,6 +743,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
 				return ERR_PARSE_ERROR;
 				return ERR_PARSE_ERROR;
 			}
 			}
 
 
+			REF ref = REF(Object::cast_to<Reference>(obj));
+
 			get_token(p_stream, token, line, r_err_str);
 			get_token(p_stream, token, line, r_err_str);
 			if (token.type != TK_COMMA) {
 			if (token.type != TK_COMMA) {
 				r_err_str = "Expected ',' after object type";
 				r_err_str = "Expected ',' after object type";
@@ -767,12 +769,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
 					}
 					}
 
 
 					if (token2.type == TK_PARENTHESIS_CLOSE) {
 					if (token2.type == TK_PARENTHESIS_CLOSE) {
-						Reference *reference = Object::cast_to<Reference>(obj);
-						if (reference) {
-							value = REF(reference);
-						} else {
-							value = obj;
-						}
+						value = ref.is_valid() ? Variant(ref) : Variant(obj);
 						return OK;
 						return OK;
 					}
 					}