UPB-CS-OpenSourceUpstream / libtock-rs

Rust userland library for Tock
Apache License 2.0
0 stars 12 forks source link

Console API - empty string bug #31

Open alexandruCarp opened 1 year ago

alexandruCarp commented 1 year ago

I was noticed by @DanutAldea that the example app for the temperature API is not working as expected on microbit:v2. I found out that the app would freeze when it tries to write an empty string (in case of positive temperature):

Ok(temp_val) => writeln!(
                Console::writer(),
                "Temperature: {}{}.{}*C\n",
                if temp_val > 0 { "" } else { "-" },
                i32::abs(temp_val) / 100,
                i32::abs(temp_val) % 100
            )

The console write function calls yield, but it never receives a callback, because the transmit buffer function from the uart driver returns a SIZE error if buffer length is 0.

A possible fix would be adding a size check in the write function of the console API, preventing it from yielding in case of an empty string. I have also tried to remove the size check from the driver, and it worked, but the other approach seems better.

@alexandruradovici , what do you think?

alexandruradovici commented 1 year ago

The correct solution is to add a check verifies if the command returns an error. Can you submit a PR with this?

alexandruCarp commented 1 year ago

I will try that and submit a PR.