Skip to content

Bug fix for char and overflow #10

Open
@tamtam22

Description

@tamtam22

serialport_read_until() method needs some optimization, in particular these 2 fixes!

  1. 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 ...

  1. 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions