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 {%- set kind = packed_field.field.kind %} |
17 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %} | 17 {%- if kind|is_object_kind %} |
| 18 {%- set wrapper_type = kind|cpp_wrapper_type %} |
| 19 {%- if not kind|is_nullable_kind %} |
| 20 if (mojo::internal::IsNonNullableValidationEnabled() && |
| 21 !object->{{name}}.offset) { |
| 22 ReportValidationError( |
| 23 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); |
| 24 return false; |
| 25 } |
| 26 {%- endif %} |
18 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { | 27 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { |
19 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); | 28 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); |
20 return false; | 29 return false; |
21 } | 30 } |
| 31 {%- if kind|is_any_array_kind or kind|is_string_kind %} |
| 32 if (!{{wrapper_type}}::Data_::Validate< |
| 33 {{kind|get_array_validate_params|indent(10)}}>( |
| 34 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
| 35 bounds_checker)) { |
| 36 {%- else %} |
22 if (!{{wrapper_type}}::Data_::Validate( | 37 if (!{{wrapper_type}}::Data_::Validate( |
23 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), | 38 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
24 bounds_checker | 39 bounds_checker)) { |
25 {%- if packed_field.field.kind|is_any_array_kind -%} | 40 {%- endif %} |
26 , {{packed_field.field.kind|expected_array_size}} | |
27 {%- endif -%} | |
28 )) { | |
29 return false; | 41 return false; |
30 } | 42 } |
31 {%- elif packed_field.field.kind|is_any_handle_kind %} | 43 {%- elif kind|is_any_handle_kind %} |
| 44 {%- if not kind|is_nullable_kind %} |
| 45 if (mojo::internal::IsNonNullableValidationEnabled() && |
| 46 object->{{name}}.value() == mojo::internal::kEncodedInvalidHandleValue) { |
| 47 ReportValidationError( |
| 48 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); |
| 49 return false; |
| 50 } |
| 51 {%- endif %} |
32 if (!bounds_checker->ClaimHandle(object->{{name}})) { | 52 if (!bounds_checker->ClaimHandle(object->{{name}})) { |
33 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); | 53 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); |
34 return false; | 54 return false; |
35 } | 55 } |
36 {%- endif %} | 56 {%- endif %} |
37 {%- endfor %} | 57 {%- endfor %} |
38 | 58 |
39 return true; | 59 return true; |
40 {%- endmacro %} | 60 {%- endmacro %} |
41 | 61 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 106 |
87 {%- macro decodes(struct) -%} | 107 {%- macro decodes(struct) -%} |
88 {%- for pf in struct.packed.packed_fields %} | 108 {%- for pf in struct.packed.packed_fields %} |
89 {%- if pf.field.kind|is_object_kind %} | 109 {%- if pf.field.kind|is_object_kind %} |
90 mojo::internal::Decode(&{{pf.field.name}}, handles); | 110 mojo::internal::Decode(&{{pf.field.name}}, handles); |
91 {%- elif pf.field.kind|is_any_handle_kind %} | 111 {%- elif pf.field.kind|is_any_handle_kind %} |
92 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); | 112 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); |
93 {%- endif %} | 113 {%- endif %} |
94 {%- endfor %} | 114 {%- endfor %} |
95 {%- endmacro -%} | 115 {%- endmacro -%} |
OLD | NEW |