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

analyze: bad parenthesization around C string literals #1189

Open
spernsteiner opened this issue Dec 9, 2024 · 1 comment
Open

analyze: bad parenthesization around C string literals #1189

spernsteiner opened this issue Dec 9, 2024 · 1 comment

Comments

@spernsteiner
Copy link
Collaborator

C code:

void ck_assert_failed(const char *filename, unsigned int line, const char *msg);

// ...
ck_assert_failed("foo", 100, "bar");

c2rust-transpile output (with manual edits to the implementation of ck_assert_failed):

pub unsafe extern "C" fn ck_assert_failed(
    mut filename: *const libc::c_char,
    mut line: libc::c_uint,
    mut msg: *const libc::c_char,
) -> ! {
    panic!();
}

ck_assert_failed(
    b"foo" as *const u8 as *const libc::c_char,
    100 as libc::c_int as libc::c_uint,
    b"bar" as *const u8 as *const libc::c_char,
);

c2rust-analyze output:

pub unsafe extern "C" fn ck_assert_failed<'h0,'h1>(
    mut filename: &'h0 (libc::c_char),
    mut line: libc::c_uint,
    mut msg: &'h1 (libc::c_char),
) -> ! {
    panic!();
}

ck_assert_failed(
    &*(b"foo\0") as *const u8 as *const libc::c_char,
    100 as libc::c_int as libc::c_uint,
    &*(b"bar\0") as *const u8 as *const libc::c_char,
);

This has type errors on the first and third arguments passed to ck_assert_failed. These arguments should instead be parenthesized like &*((b"foo\0") as *const u8 as *const libc::c_char).

@fw-immunant
Copy link
Contributor

This looks similar to the issue fixed in #1121, and probably has a similar fix.

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

No branches or pull requests

2 participants