OLD | NEW |
1 {%- macro validate(struct, class_name) %} | 1 {%- macro validate(struct, class_name) %} |
2 if (!data) | 2 if (!data) |
3 return true; | 3 return true; |
4 | 4 |
5 if (!ValidateStructHeader( | 5 if (!ValidateStructHeader( |
6 data, sizeof({{class_name}}), | 6 data, sizeof({{class_name}}), |
7 {{struct.packed.packed_fields|length}}, bounds_checker)) { | 7 {{struct.packed.packed_fields|length}}, bounds_checker)) { |
8 return false; | 8 return false; |
9 } | 9 } |
10 | 10 |
11 const {{class_name}}* MOJO_ALLOW_UNUSED object = | 11 const {{class_name}}* MOJO_ALLOW_UNUSED object = |
12 static_cast<const {{class_name}}*>(data); | 12 static_cast<const {{class_name}}*>(data); |
13 | 13 |
14 {%- for packed_field in struct.packed.packed_fields %} | 14 {%- for packed_field in struct.packed.packed_fields %} |
15 {%- set name = packed_field.field.name %} | 15 {%- set name = packed_field.field.name %} |
16 {%- if packed_field.field.kind|is_object_kind %} | 16 {%- if packed_field.field.kind|is_object_kind %} |
17 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %} | 17 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %} |
18 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset) || | 18 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { |
19 !{{wrapper_type}}::Data_::Validate( | 19 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); |
| 20 return false; |
| 21 } |
| 22 if (!{{wrapper_type}}::Data_::Validate( |
20 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), | 23 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
21 bounds_checker)) { | 24 bounds_checker)) { |
22 return false; | 25 return false; |
23 } | 26 } |
24 {%- elif packed_field.field.kind|is_handle_kind %} | 27 {%- elif packed_field.field.kind|is_handle_kind %} |
25 if (!bounds_checker->ClaimHandle(object->{{name}})) | 28 if (!bounds_checker->ClaimHandle(object->{{name}})) { |
| 29 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); |
26 return false; | 30 return false; |
| 31 } |
27 {%- endif %} | 32 {%- endif %} |
28 {%- endfor %} | 33 {%- endfor %} |
29 | 34 |
30 return true; | 35 return true; |
31 {%- endmacro %} | 36 {%- endmacro %} |
32 | 37 |
33 {%- macro field_line(field) %} | 38 {%- macro field_line(field) %} |
34 {%- set type = field.kind|cpp_field_type %} | 39 {%- set type = field.kind|cpp_field_type %} |
35 {%- set name = field.name -%} | 40 {%- set name = field.name -%} |
36 {%- if field.kind.spec == 'b' -%} | 41 {%- if field.kind.spec == 'b' -%} |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 82 |
78 {%- macro decodes(struct) -%} | 83 {%- macro decodes(struct) -%} |
79 {%- for pf in struct.packed.packed_fields %} | 84 {%- for pf in struct.packed.packed_fields %} |
80 {%- if pf.field.kind|is_object_kind %} | 85 {%- if pf.field.kind|is_object_kind %} |
81 mojo::internal::Decode(&{{pf.field.name}}, handles); | 86 mojo::internal::Decode(&{{pf.field.name}}, handles); |
82 {%- elif pf.field.kind|is_handle_kind %} | 87 {%- elif pf.field.kind|is_handle_kind %} |
83 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); | 88 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); |
84 {%- endif %} | 89 {%- endif %} |
85 {%- endfor %} | 90 {%- endfor %} |
86 {%- endmacro -%} | 91 {%- endmacro -%} |
OLD | NEW |