Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl

Issue 2286513002: Mojo C++ bindings: fix inlined union validation. (Closed)
Patch Set: add a test case Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f151a4e245cbb72298def31c840e05b6d9e05e44..af5ea9f8a8340512fdcd0784905ebf30b7077573 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
@@ -7,15 +7,27 @@ bool {{class_name}}::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context,
bool inlined) {
- if (!data)
+ if (!data) {
+ DCHECK(!inlined);
return true;
+ }
+
+ // If it is inlined, the alignment is already enforced by its enclosing
+ // object. We don't have to validate that.
+ DCHECK(!inlined || mojo::internal::IsAligned(data));
- if (!ValidateUnionHeaderAndClaimMemory(data, inlined, validation_context))
+ if (!inlined &&
+ !mojo::internal::ValidateNonInlinedUnionHeaderAndClaimMemory(
+ data, validation_context)) {
return false;
+ }
const {{class_name}}* object = static_cast<const {{class_name}}*>(data);
ALLOW_UNUSED_LOCAL(object);
+ if (inlined && object->is_null())
+ return true;
+
switch (object->tag) {
{% for field in union.fields %}
case {{enum_name}}::{{field.name|upper}}: {
« no previous file with comments | « mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698