Skip to content

Translate access to flexible array member#165

Merged
nunoplopes merged 1 commit into
Cpp2Rust:masterfrom
lucic71:fam
Jun 1, 2026
Merged

Translate access to flexible array member#165
nunoplopes merged 1 commit into
Cpp2Rust:masterfrom
lucic71:fam

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented Jun 1, 2026

Changed the access pattern of flexible arrays from

let bytes: [u8; 1] = ...;
bytes[10] = ...

to

let bytes: [u8; 1] = ...;
*bytes.as_mut_ptr().add(10) = ...;

The original access panics because the bounds are violated, i.e. accessing the 10th element in an array declared with 1 element. The new access does not panic, it preserves the C/C++ behavior.

@nunoplopes nunoplopes merged commit ce0af71 into Cpp2Rust:master Jun 1, 2026
9 checks passed
lucic71 added a commit to lucic71/cpp2rust that referenced this pull request Jun 4, 2026
Changed the access pattern of flexible arrays from

```rs
let bytes: [u8; 1] = ...;
bytes[10] = ...
```

to

```rs
let bytes: [u8; 1] = ...;
*bytes.as_mut_ptr().add(10) = ...;
```

The original access panics because the bounds are violated, i.e.
accessing the 10th element in an array declared with 1 element. The new
access does not panic, it preserves the C/C++ behavior.
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

Successfully merging this pull request may close these issues.

2 participants