Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
josephduchesne opened this issue Nov 23, 2024 · 1 comment
Open

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

josephduchesne opened this issue Nov 23, 2024 · 1 comment

Comments

@josephduchesne
Copy link

josephduchesne commented Nov 23, 2024

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);.

@mcsauder
Copy link
Collaborator

Thanks @josephduchesne! If you'd like to submit a PR I'd be happy to review it!

-Mark

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants