c is int with an unsigned value 0xCA.
t->str is const char * with (on Arduino Mega 2560 R3) a signed value -54 decimal which as an unsigned value is 0xCA.
In the comparison, the char is sign extended to an int, resulting in 0xFFFFFFCA giving:
if (0xCA == 0xFFFFFFCA) {
This is never true and not the intention. There appear to be other comparisons in Stream.cpp with this problem.
This code hangs forever, even when Serial repeatedly receives 0xCA, tested on Arduino Mega 2560 R3:
The reason is in Stream
findMulti
: https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Stream.cpp#L270Consider this comparison:
c
isint
with an unsigned value 0xCA.t->str
isconst char *
with (on Arduino Mega 2560 R3) a signed value -54 decimal which as an unsigned value is 0xCA. In the comparison, the char is sign extended to an int, resulting in 0xFFFFFFCA giving:This is never true and not the intention. There appear to be other comparisons in Stream.cpp with this problem.