Skip to content

arm_semihosting.zig – could @constCast cause a HardFault on read‑only memory? #986

Description

@by965738071

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions