Skip to content

Commit

Permalink
Fix Android and Java codegen for bitmaps.
Browse files Browse the repository at this point in the history
We were casting to the BitMask type, which did implicit conversions to its IntegerType.
And those could fail if the java primitive type ended up wider than IntegerType.
  • Loading branch information
bzbarsky-apple authored and jadhavrohit924 committed May 19, 2023
1 parent 14e310a commit 34520e1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{%- elif encodable.is_enum -%}
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().IntegerToPrimitive({{source}}));
{%- elif encodable.is_bitmap -%}
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().{{encodable.boxed_java_type}}ToPrimitive({{source}}));
{{target}}.SetRaw(static_cast<std::remove_reference_t<decltype({{target}})>::IntegerType>(chip::JniReferences::GetInstance().{{encodable.boxed_java_type}}ToPrimitive({{source}})));
{% else -%}
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().{{encodable.boxed_java_type}}ToPrimitive({{source}}));
{% endif -%}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/partials/encode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().{{asJavaType type null parent.parent.name forceNotList=true}}ToPrimitive({{source}}));
{{else}}
{{#if_is_bitmap type}}
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().{{asJavaType type null parent.parent.name forceNotList=true}}ToPrimitive({{source}}));
{{target}}.SetRaw(static_cast<std::remove_reference_t<decltype({{target}})>::IntegerType>(chip::JniReferences::GetInstance().{{asJavaType type null parent.parent.name forceNotList=true}}ToPrimitive({{source}})));
{{else}}
{{target}} = static_cast<std::remove_reference_t<decltype({{target}})>>(chip::JniReferences::GetInstance().{{asJavaType type null parent.parent.name forceNotList=true}}ToPrimitive({{source}}));
{{/if_is_bitmap}}
Expand Down
Loading

0 comments on commit 34520e1

Please sign in to comment.