Skip to content

Commit

Permalink
Fix detection of negative integers when floating point is expected. (p…
Browse files Browse the repository at this point in the history
…roject-chip#19821)

Our "see if it's an integer and append .0" code for floating point
only detected positive integers, so we were ending up with things like
"-1f" in generated code, which does not compile.

Fixes project-chip#19800
  • Loading branch information
bzbarsky-apple authored Jun 22, 2022
1 parent cabb0df commit 51d633a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_MC_6_4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ tests:
value: 0

- label: "Reads the PlaybackSpeed attribute from the DUT"
disabled: true
command: "readAttribute"
attribute: "PlaybackSpeed"
response:
Expand All @@ -142,7 +141,6 @@ tests:
value: "Verify that the media play has reversed direction"

- label: "Reads the PlaybackSpeed attribute from the DUT"
disabled: true
command: "readAttribute"
attribute: "PlaybackSpeed"
response:
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ async function asTypedLiteral(value, type, cookie)
// If the number looks like an integer, append ".0" to the end;
// otherwise adding an "f" suffix makes compilers complain.
value = value.toString();
if (value.match(/^[0-9]+$/)) {
if (value.match(/^-?[0-9]+$/)) {
value = value + ".0";
}
return value + 'f';
Expand Down
66 changes: 46 additions & 20 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51d633a

Please sign in to comment.