-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
serialport_read_until() method needs some optimization, in particular these 2 fixes!
- More proper way to declare char:
char b[1]; change to char b;
int n = read(fd, b, 1); change to int n = read(fd, &b, 1);
buf[i] = b[0]; change to buf[i] = b;
while( b[0] != until ... change to while( b != until ...
- Overflow problem
while( ... && i < buf_max ... change to while( ... && i+1 < buf_max ...
Unless the documentation says that buf_max should be one less than the size of the buffer (which would be counterintuitive and error-prone)
Also, since i is checked at the end, even with this fix, the code will still store one byte if you pass in buf_max == 0 (but without the fix it will store two bytes). So that's another bug.
Metadata
Metadata
Assignees
Labels
No labels