Index: mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl |
index 9f6f02f0d8a525d480effd45bccce100619bfbfc..b9c633974f9dc8fcaaffbe86f41606e6faa0f29a 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl |
@@ -9,7 +9,8 @@ |
// static |
bool {{class_name}}::Validate(const void* data, |
- mojo::internal::BoundsChecker* bounds_checker) { |
+ mojo::internal::BoundsChecker* bounds_checker, |
+ bool inlined) { |
if (!data) { |
return true; |
} |
@@ -19,7 +20,10 @@ bool {{class_name}}::Validate(const void* data, |
return false; |
} |
- if (!bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { |
+ // If the union is inlined in another structure its memory was already claimed. |
+ // This ONLY applies to the union itself, NOT anything which the union points |
+ // to. |
+ if (!inlined && !bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { |
ReportValidationError( |
mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
return false; |