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);.
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 sincewhile (next_char != lineTerminator)if lineTerminator is '\0' and next_char is also 0 initially. So the first run of the check iswhile( 0 != 0)and the loop body never executes.This can be fixed by checking
while (next_char != lineTerminator || dataString.length() == 0)instead, adding a booleanfirst_runflag and a similar check, or switching todo{...}while(next_char != lineTerminator);.