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

Undefined behavior on 16 bit architectures #982

Closed
d2weber opened this issue Sep 10, 2024 · 1 comment
Closed

Undefined behavior on 16 bit architectures #982

d2weber opened this issue Sep 10, 2024 · 1 comment

Comments

@d2weber
Copy link
Contributor

d2weber commented Sep 10, 2024

When I checked out this crate and used it as a path dependency, cargo warns be about several places with undefined behavior.

To reproduce:

git clone [email protected]:smoltcp-rs/smoltcp.git --branch v0.10.0

In a crate that uses a target with "target-pointer-width": "16" specify in Cargo.toml (assuming the directories are next to each other):

[dependency.smoltcp]
path= "../smoltcp"

When building/checking in the crate with the 16 bit target, cargo yields:

error: this arithmetic operation will overflow
   --> /home/dweber/gh/smoltcp/src/socket/tcp.rs:489:26
    |
489 |         if rx_capacity > (1 << 30) {
    |                          ^^^^^^^^^ attempt to shift left by `30_i32`, which would overflow
    |
    = note: `#[deny(arithmetic_overflow)]` on by default

error: this arithmetic operation will overflow
   --> /home/dweber/gh/smoltcp/src/socket/tcp.rs:597:13
    |
597 |             (1 << 16) - 1,
    |             ^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow

error: this arithmetic operation will overflow
    --> /home/dweber/gh/smoltcp/src/socket/tcp.rs:2158:63
     |
2158 |                 repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16;
     |                                                               ^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow

Note: if I specify the dependency as usual (smoltcp= "0.10.0"), these warnings won't appear but the behavior is still undefined.

d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 10, 2024
d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 10, 2024
d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 10, 2024
d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 18, 2024
d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 18, 2024
d2weber added a commit to d2weber/smoltcp that referenced this issue Sep 23, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 23, 2024
@thvdveld
Copy link
Contributor

Fixed in #983 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants