Skip to content

Commit

Permalink
Make contains/excludes constraints compile for lists of unsigned values.
Browse files Browse the repository at this point in the history
Two changes here:

1) In chip_tests_iterate_expected_list, we were marking each individual value as
   an array (because "this.isArray" would be true in general when this helper is
   used).  That caused asTypedLiteral to fail to map it to an integer basic type
   and hence we were not adding with the proper suffixes, and that lead to
   signed-to-unsigned comparison errors.  This is the actual bugfix.

2) In asTypedLiteral, we really should be suffixing uint8_t with "U".  It's not
   clear why compilers don't complain about signed-to-unsigned compares for that
   type the way they do for uint16/32/64_t, but conceptually this is the right
   thing to do.

Fixes #19726
  • Loading branch information
bzbarsky-apple committed Jun 17, 2022
1 parent 147cab2 commit 27b4b2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,8 @@ function chip_tests_iterate_expected_list(values, options)
{
values = values.map(value => {
return {
global: this.global, parent: this.parent, name: this.name, type: this.type, isArray: this.isArray,
isNullable: this.isNullable, value: value,
global: this.global, parent: this.parent, name: this.name, type: this.type, isArray: false,
isNullable: false, value: value,
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ async function asTypedExpression(value, type)
return `static_cast<${resultType}>(${value})`;
}

async function asTypedLiteral(value, type)
async function asTypedLiteral(value, type, cookie)
{
const valueIsANumber = !isNaN(value);
if (!valueIsANumber) {
Expand All @@ -335,6 +335,7 @@ async function asTypedLiteral(value, type)
return value + 'L';
case 'int64_t':
return value + 'LL';
case 'uint8_t':
case 'uint16_t':
return value + 'U';
case 'uint32_t':
Expand Down

0 comments on commit 27b4b2b

Please sign in to comment.