summaryrefslogtreecommitdiff
path: root/nrf-softdevice-gen/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'nrf-softdevice-gen/src/main.rs')
-rw-r--r--nrf-softdevice-gen/src/main.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/nrf-softdevice-gen/src/main.rs b/nrf-softdevice-gen/src/main.rs
index fd30102..4ee2bf0 100644
--- a/nrf-softdevice-gen/src/main.rs
+++ b/nrf-softdevice-gen/src/main.rs
@@ -85,6 +85,13 @@ fn main() {
}
gen_bindings(&tmp_dir, &src_dir, &tmp_bindings_path, |data| {
+ // Change all "dynamically-sized" arrays from length 1 to length 0.
+ // This avoids UB when creating Rust references to structs when the length is 0.
+ //
+ // We can't use a "real" flexible array ([] instead of [0]) because
+ // they're used inside enums :(
+ let data = data.replace("[1];", "[0];");
+
let re = Regex::new(r"SVCALL\((?P<svc>[A-Za-z0-9_]+),\s*(?P<ret>[A-Za-z0-9_]+),\s*(?P<name>[A-Za-z0-9_]+)\((?P<args>.*)\)\);").unwrap();
re.replace_all(&data, "$ret $name($args);").into()
});