rust-embedded / cortex-m-semihosting

Semihosting for ARM Cortex-M processors
Apache License 2.0
40 stars 19 forks source link

write_all crashes if syscall fails #4

Closed zargony closed 7 years ago

zargony commented 7 years ago

If syscall! fails and returns -1 inside write_all, it crashes because the write_all loop still tries to calculate the new buffer offset. Maybe syscall! should return isize (or c_int?). Gdb seems to report back -1 if a hostio call fails (just like libc does on the host).

For some reason all writes to stdout fail for me (syscall returning -1), while stderr works fine. (SAM3X, black magic probe 1.6, gdb 7.10.1, rustc nightly 2017-05-01)

alexisvl commented 7 years ago

Nice timing, I just ran into this one this morning. Honestly I'm kinda floored by write_all() just unsafe stuffing the return value into a slice length without validating it. Maybe I'll PR a fix later.

alexisvl commented 7 years ago

@zargony wait until you hear why gdb returns -1 for writes to stdout. I'm about to file another issue. :)