Skip to content

SerialPort::ReadLine returns 0 bytes if lineTerminator == 0 #193

@josephduchesne

Description

@josephduchesne

I'm trying to read some COBS encoded serial data, which uses a null character (0, or '\0' as a char literal escape sequence).

There is a logic error in ReadLine's while loop condition:

next_char is initialised as zero: unsigned char next_char = 0 ;, so on first entry to the while loop, the check fails since while (next_char != lineTerminator) if lineTerminator is '\0' and next_char is also 0 initially. So the first run of the check is while( 0 != 0) and the loop body never executes.

This can be fixed by checking while (next_char != lineTerminator || dataString.length() == 0) instead, adding a boolean first_run flag and a similar check, or switching to do{...}while(next_char != lineTerminator);.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions