transpile: Do not leak main argument strings#1447
Conversation
e10b712 to
2f26db6
Compare
kkysen
left a comment
There was a problem hiding this comment.
Can you add a snapshot test for this, too?
326ac44 to
ba0f652
Compare
kkysen
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.