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

use Box::leak instead of forget #8

Closed
wants to merge 10 commits into from
Closed

Conversation

pchampin
Copy link
Owner

attempt to address #5

@pchampin
Copy link
Owner Author

@mkatychev, could you check whether this solves the problem described in #5?

@mkatychev
Copy link
Contributor

mkatychev commented Aug 20, 2024

@pchampin this does indeed solve the problem. ideally I would like a unit tests that would cover this scenario to prevent regression.

The test_hash unit tests managed to reproduce the scenario best. On latest master, inserting mown1 and using println! on it seems to do the UB.

A CI miri test would also help avoid this in the future.

Addressing some of the clippy problems (such as the MownStr::from_str method name) for a new (non-hotfix) release would also be helpful.

Let me know if you'd like some help with the unit test/CI miri work.

@pchampin
Copy link
Owner Author

Let me know if you'd like some help with the unit test/CI miri work.

Yes, that would be very much appreciated. 👍

@pchampin pchampin marked this pull request as ready for review September 6, 2024 16:33
src/lib.rs Outdated
@@ -474,10 +472,11 @@ mod test {
}

#[cfg(target_os = "linux")]
#[cfg_attr(miri, ignore)]
Copy link
Contributor

@mkatychev mkatychev Sep 7, 2024

Choose a reason for hiding this comment

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

would it be better to have CI be noisy here? This may help hide underlying issues.
EDIT: I was not able to actually run the CI jobs myself, going off of this, I would suggest this be added to miri test:

- uses: dtolnay/rust-toolchain@nightly

with:
  components: miri

Copy link
Owner Author

Choose a reason for hiding this comment

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

would it be better to have CI be noisy here? This may help hide underlying issues.

I marked this test as ignored because it accesses the filesystem, which miri can't do (sandboxing issue). This is not related to the code of mownstr but to the code of the test itself, so I don't think it is a significant issue to report.

I would suggest this be added to miri test:

Yes, I added the "with" directive in a further commit: 05c3350

Copy link
Contributor

Choose a reason for hiding this comment

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

Could this instead be done on the locations where m0 and m1 are defined & invoked so that there's still miri coverage? That may be overzealous but this would give us miri coverage of

mownstr/src/lib.rs

Lines 491 to 498 in 815c793

let s = unsafe { String::from_utf8_unchecked(vec![b'a' + i; CAP]) };
v.push(MownStr::from(s));
println!(
"{} MownStr(s) in the Vec, of len {}, starting with {:?}",
v.len(),
v[v.len() - 1].len(),
&v[v.len() - 1][..2]
);

Copy link
Owner Author

Choose a reason for hiding this comment

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

fair enough, I will proceed otherwise

Copy link
Owner Author

Choose a reason for hiding this comment

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

solved by d27f233

Copy link
Contributor

@mkatychev mkatychev left a comment

Choose a reason for hiding this comment

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

Thank you!

@pchampin
Copy link
Owner Author

I merged this branch locally, but for some reason github does not see it as merged, and complains about conflicts with the 'main' branch. This is probably due to the fact that I merged 'main' in this PR at some point...

Closing it, but note that it was effectively merged.

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.

2 participants