core/src/core/arm_semihosting.zig
Lines: 89–96
Hi,I was looking at this piece of code and I have a question about safety.
The function receives data as []const u8, but then uses @constcast to turn it into []u8 and modifies the last byte (first setting it to 0, later restoring the original value).
In embedded systems, the caller might pass a string literal that lives in flash (read‑only memory). If that happens, wouldn’t that write operation trigger a HardFault? Or is the caller expected to always provide a buffer in RAM?
I’m not sure if I’m missing something – maybe the design assumes that the input is always writable? If not, would it be safer to copy the data to a temporary buffer before modifying it?
I’d appreciate your thoughts on this. Thanks!
core/src/core/arm_semihosting.zig
Lines: 89–96
Hi,I was looking at this piece of code and I have a question about safety.
The function receives data as []const u8, but then uses @constcast to turn it into []u8 and modifies the last byte (first setting it to 0, later restoring the original value).
In embedded systems, the caller might pass a string literal that lives in flash (read‑only memory). If that happens, wouldn’t that write operation trigger a HardFault? Or is the caller expected to always provide a buffer in RAM?
I’m not sure if I’m missing something – maybe the design assumes that the input is always writable? If not, would it be safer to copy the data to a temporary buffer before modifying it?
I’d appreciate your thoughts on this. Thanks!