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

UI::queue_main and UI::on_should_quit are unsound #41

Closed
jonas-schievink opened this issue Oct 17, 2018 · 5 comments
Closed

UI::queue_main and UI::on_should_quit are unsound #41

jonas-schievink opened this issue Oct 17, 2018 · 5 comments
Labels
c-bug Bug - some feature is not working as expected p-high High Priority
Milestone

Comments

@jonas-schievink
Copy link

This program prints garbage to the console on my system:

    let ev = iui::UI::init().unwrap();

    {
        let v = vec![1, 2, 3, 4];
        ev.queue_main(|| {
            for i in &v {
                println!("{}", i);
            }
        });
    }

    ev.main();

This is a use-after-free on the vector v and should not compile. Both UI::queue_main and UI::on_should_quit must require the callback to be 'static.

This is probably the case for all functions that take a callback, not just those 2, but I just started using iui, so I don't which (if any) other functions are affected.

You can test that this code example doesn't compile using compiletest-rs.

@jonas-schievink
Copy link
Author

Also affected:

  • Window::on_closing
  • Button::on_clicked
  • Checkbox::on_toggled
  • Combobox::on_selected
  • ...probably most controls are affected

@NoraCodes
Copy link
Collaborator

You're absolutely right, thank you! They do need a 'static bound.

@NoraCodes NoraCodes added c-bug Bug - some feature is not working as expected p-high High Priority labels Oct 17, 2018
@jonas-schievink
Copy link
Author

Err, this still seems to compile as of 2e3343b

@NoraCodes
Copy link
Collaborator

D'oh. I didn't push the second commit.
Let's add some shouldn't-compile tests...

@NoraCodes NoraCodes reopened this Dec 3, 2018
@NoraCodes
Copy link
Collaborator

I can't seem to actually make them sound without adding a 'static bound, which is annoying but is also the way that gtk-rs does it and is probably the way to go :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-bug Bug - some feature is not working as expected p-high High Priority
Projects
None yet
Development

No branches or pull requests

2 participants