Skip to content

Integer literal overflow in C causes Rust compilation error #1435

@HurryPeng

Description

@HurryPeng

C source code (from LibmCS):

int32_t sign = 0x80000000U;

C2Rust 0.21.0 translates it to:

pub type int32_t = __int32_t;
pub type __int32_t = i32;
let mut sign: int32_t = 0x80000000 as int32_t;

which causes this compilation error:

error: literal out of range for `i32`
  --> src/mathd/sqrtd.rs:42:29
   |
42 |     let mut sign: int32_t = 0x80000000 as int32_t;
   |                             ^^^^^^^^^^
   |
   = note: `#[deny(overflowing_literals)]` on by default
   = note: the literal `0x80000000` (decimal `2147483648`) does not fit into the type `i32` and will become `-2147483648i32`
   = help: consider using the type `u32` instead

C2Rust 0.20.0 translates that to:

pub type int32_t = __int32_t;
pub type __int32_t = libc::c_int;
let mut sign: int32_t = 0x80000000 as libc::c_uint as int32_t;

which compiles.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions