ARMmbed / ATParser

Parser for AT commands and similar protocols.
35 stars 27 forks source link

Accessing a negative index #12

Open soramame21 opened 6 years ago

soramame21 commented 6 years ago

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++;
geky commented 6 years ago

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.

soramame21 commented 6 years ago

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