Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong cast in morse app #2436

Merged
merged 2 commits into from
Dec 20, 2024
Merged

fix wrong cast in morse app #2436

merged 2 commits into from
Dec 20, 2024

Conversation

zxkmm
Copy link
Contributor

@zxkmm zxkmm commented Dec 19, 2024

  • the new cpp syntex from some of the standard (iirc 11) don't need the (void)xxx. just give the type in argument and don't name it
  • the original cast for bool is wrong, it would always cast to true
  • this fix appear after Morse transmitter loop freeze #2430, the issue there isn't caused by here

@zxkmm zxkmm marked this pull request as ready for review December 19, 2024 14:09
@zxkmm zxkmm enabled auto-merge (squash) December 19, 2024 14:10
@zxkmm zxkmm marked this pull request as draft December 19, 2024 17:17
auto-merge was automatically disabled December 19, 2024 17:17

Pull request was converted to draft

@zxkmm zxkmm marked this pull request as ready for review December 19, 2024 18:22
@zxkmm zxkmm enabled auto-merge (squash) December 19, 2024 18:23
Copy link
Member

@gullradriel gullradriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go

@zxkmm zxkmm merged commit 55525ed into portapack-mayhem:next Dec 20, 2024
3 checks passed
zxkmm added a commit to zxkmm/mayhem-firmware that referenced this pull request Dec 27, 2024
* fix wrong cast

* sorry, forgot to use enum
(void)i; // avoid unused warning
mode_cw = (bool)value;
options_modulation.on_change = [this](size_t, OptionsField::value_t v) {
mode_cw = (bool)v;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why static_cast doesn't fit the purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think static_cast would work too. But imo in this situation, enum is the safest way and best practice for safety and reliability.

Maybe static cast can save some ram usage? Not sure, if you know more info feel free to send a PR and I’ll review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: readability

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general static_cast is more strict than a regular c-style-cast that can behave as reinterpret_cast in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure if you meant:

  1. the enum isn't necessary, just static_cast value and give to mode_cw
  2. we static_cast based on my change instead of c style cast (bool)

If you meant the first way then im afraid it doesn't make sense, im on phone and didn't take a look of how OptionsField class implemented, but iirc the old usage is wrong, even if you static_cast there, it still will cast to always true.

If you meant the second, I think it's not necessary because it's already protected by enum and no edge case could happen, but if you still want (and have your reason), you and I can change it. afaik all cpp syntax sugar could somehow cost more spaces.

In any case I suggest you to make a PR, and we'll discuss there, instead of email-spam, because if we discuss here, not only me but all the reviewer will be spammed by email in each convo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants