This code hangs forever, even when Serial1 repeatedly receives 0xCA:
while (!Serial1.find(0xCA)) ;
The reason is in Stream::findMulti:
|
if (c == t->str[t->index]) { |
Consider a comparison where:
c is int with an unsigned value 0xCA.
t->str is const char * with 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.
Additional context
Tested on Arduino Mega 2560 R3.
Related
This code hangs forever, even when
Serial1repeatedly receives0xCA:The reason is in
Stream::findMulti:ArduinoCore-avr/cores/arduino/Stream.cpp
Line 270 in 86df345
Consider a comparison where:
cisintwith an unsigned value0xCA.t->strisconst char *with a signed value-54decimal, which as an unsigned value is0xCA.In the comparison, the char is sign extended to an
int, resulting in0xFFFFFFCAgiving:This is never
trueand not the intention. There appear to be other comparisons inStream.cppwith this problem.Additional context
Tested on Arduino Mega 2560 R3.
Related