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: use of uninitialized value in command_option copy ctor #1044

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

rept1d
Copy link
Contributor

@rept1d rept1d commented Dec 19, 2023

Basically all examples of using dpp::command_option invoke undefined behavior. Let's look at its typical usage example from the docs:

dpp::slashcommand newcommand("blep", "Send a random adorable animal photo", bot.me.id);
newcommand.add_option(
    dpp::command_option(dpp::co_string, "animal", "The type of animal", true)
);

The problem here is that dpp::command_option::command_option does not initialize a boolean field called focused. And then inside add_option the implicitly-defined copy constructor is called. This constructor, among other things, copies that focused field, but since it was never initialized, we get UB.

This PR ensures that focused is initialized in dpp::command_option::command_option with false.

Code change checklist

  • I have ensured that all methods and functions are fully documented using doxygen style comments.
  • My code follows the coding style guide.
  • I tested that my change works before raising the PR.
  • I have ensured that I did not break any existing API calls.
  • I have not built my pull request using AI, a static analysis tool or similar without any human oversight.

Copy link

netlify bot commented Dec 19, 2023

Deploy Preview for dpp-dev ready!

Name Link
🔨 Latest commit 5ad2c5d
🔍 Latest deploy log https://app.netlify.com/sites/dpp-dev/deploys/65815521ee55190008f93869
😎 Deploy Preview https://deploy-preview-1044--dpp-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the code Improvements or additions to code. label Dec 19, 2023
Copy link
Contributor

@Jaskowicz1 Jaskowicz1 left a comment

Choose a reason for hiding this comment

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

I'm honestly surprised this didn't already exist lol

@braindigitalis
Copy link
Contributor

the reason this never caused an issue is because focused is only set in an auto complete event at which point it is explicitly set to true or false on each event. this just squashes warnings/static analysis errors and makes things clean and explicit. looks good.

@Jaskowicz1 Jaskowicz1 merged commit ccc7133 into brainboxdotcc:dev Dec 19, 2023
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Improvements or additions to code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants