ATParser icon indicating copy to clipboard operation
ATParser copied to clipboard

Accessing a negative index

Open soramame21 opened this issue 8 years ago • 2 comments

I read following code and found next line is accessing a negative index. Is it true? response[i+1-_recv_delim_size] I assume following conditions. i=0, recv_delim_size=2, recv_delimiter="\r\n"

bool ATParser::vrecv(const char *response, va_list args)

        int i = 0;
        int offset = 0;

        while (response[i]) {
            if (memcmp(&response[i+1-_recv_delim_size], _recv_delimiter, _recv_delim_size) == 0) {
                i++;

soramame21 avatar Sep 02 '17 09:09 soramame21

That is a good catch! Although now I'm not sure what that line is doing exactly.

I think it should be replaced with

if (strncmp(&response[i], _recv_delimiter, _recv_delim_size) == 0) {
    i += _recv_delim_size;
    break;

This will need some testing to make sure.

geky avatar Sep 05 '17 17:09 geky

@geky I see. Thanks for reply and the fix.

soramame21 avatar Sep 06 '17 01:09 soramame21