Skip to content

Console API - empty string bug #31

@alexandruCarp

Description

@alexandruCarp

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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