-
Notifications
You must be signed in to change notification settings - Fork 13.3k
cbuf.h read() and peek() wrong return type! (not int) #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What exactly is not working? Could you please post an example sketch? I think in WiFiClient.cpp I always call getSize() before calling read and peek, so this shouldn't be a problem. Will change the return type, just wondering why this would be an issue. |
Oh, right, that's HardwareSerial. Forgot to add a check there. |
example: char buf[16];
Serial.begin(9600);
int c = Serial.readBytesUntil((char) 0x03, buf, 16); //<- instant return buffer full of gabage (0xFF) reason: size_t ICACHE_FLASH_ATTR Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
if (length < 1) return 0;
size_t index = 0;
while (index < length) {
int c = timedRead(); // <--- int here
if (c < 0 || c == terminator) break;
*buffer++ = (char)c;
index++;
}
return index; // return number of characters, not including null terminator
} // private method to read stream with timeout
int ICACHE_FLASH_ATTR Stream::timedRead()
{
int c;
_startMillis = millis();
do {
c = read(); // <--- int here
if (c >= 0) return c;
yield();
} while(millis() - _startMillis < _timeout);
return -1; // -1 indicates timeout
} int ICACHE_FLASH_ATTR HardwareSerial::read(void)
{
return _rx_buffer->read(); // <--- no int here
} char read() // <--- no int here
{
if (getSize() == 0)
return -1; // <--- no int type cast to char --> result 0xFF
char result = *_begin;
if (++_begin == _bufend)
_begin = _buf;
return result;
} |
chadouming
pushed a commit
to chadouming/Arduino
that referenced
this issue
Jul 1, 2015
igrr
added a commit
that referenced
this issue
Oct 29, 2015
ascillato
pushed a commit
to ascillato/Arduino
that referenced
this issue
Nov 12, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
read() and peek() in cbuf.h hast return type char this is wrong!
need to be int
int read()
int peek()
if not readBytesUntil for example is not working.
The text was updated successfully, but these errors were encountered: