-
Notifications
You must be signed in to change notification settings - Fork 283
transpile: Do not leak main argument strings
#1447
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
Conversation
e10b712 to
2f26db6
Compare
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a snapshot test for this, too?
326ac44 to
ba0f652
Compare
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, can you also do the thing where the snapshot test is added first before the fix, then updated along with the fix? Thanks!
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Sorry it took me a while to get back around to this. Just a couple minor comment things I think would be helpful.
| vec![mk().method_call_expr( | ||
| mk().method_call_expr( | ||
| mk().call_expr( | ||
| // TODO(kkysen) change `"std"` to `"alloc"` after `#![feature(alloc_c_string)]` is stabilized in `1.63.0` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we can switch to it now. rust-lang/rust#99277 was merged on 2022-07-16, before 2022-08-08.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing std to alloc doesn't seem to work:
failed to resolve: use of unresolved module or unlinked crate
alloc
I guess that it's not as simple as just swapping out one for the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think we also need to add extern crate alloc;. We can do that separately then, and just leave the comment here for now.
…` generated is detected as a test When testing `main.c`, `main.rs` is generated, and `cargo` thinks `c2rust-transpile/tests/snapshots/main.rs` is a second `snapshots` test, in addition to `c2rust-transpile/tests/snapshots.rs`: ```shell ❯ cargo test -p c2rust-transpile error: failed to load manifest for workspace member `/home/kkysen/work/c2rust/c2rust` Caused by: failed to load manifest for dependency `c2rust-transpile` Caused by: failed to parse manifest at `/home/kkysen/work/c2rust/c2rust-transpile/Cargo.toml` Caused by: found duplicate test name snapshots, but all test targets must have a unique name ``` This was from #1447, but wasn't caught in CI because it only runs `cargo test` a single time.
…generated is detected as a test When testing `main.c`, `main.rs` is generated, and `cargo` thinks `c2rust-transpile/tests/snapshots/main.rs` is a second `snapshots` test, in addition to `c2rust-transpile/tests/snapshots.rs`: ```shell ❯ cargo test -p c2rust-transpile error: failed to load manifest for workspace member `/home/kkysen/work/c2rust/c2rust` Caused by: failed to load manifest for dependency `c2rust-transpile` Caused by: failed to parse manifest at `/home/kkysen/work/c2rust/c2rust-transpile/Cargo.toml` Caused by: found duplicate test name snapshots, but all test targets must have a unique name ``` This was from #1447, but wasn't caught in CI because it only runs `cargo test` a single time.
…generated is detected as a test (#1499) When testing `main.c`, `main.rs` is generated, and `cargo` thinks `c2rust-transpile/tests/snapshots/main.rs` is a second `snapshots` test, in addition to `c2rust-transpile/tests/snapshots.rs`: ```shell ❯ cargo test -p c2rust-transpile error: failed to load manifest for workspace member `/home/kkysen/work/c2rust/c2rust` Caused by: failed to load manifest for dependency `c2rust-transpile` Caused by: failed to parse manifest at `/home/kkysen/work/c2rust/c2rust-transpile/Cargo.toml` Caused by: found duplicate test name snapshots, but all test targets must have a unique name ``` This was from #1447, but wasn't caught in CI because it only runs `cargo test` a single time.
mainleaks memory ofargs#649.I opted to store the final strings as
Vec<u8>rather than asCString, because the latter does not have a way to get a mutable pointer/reference without leaking it. This is because of the nul termination invariant thatCStringmust uphold.