ATParser
ATParser copied to clipboard
Accessing a negative index
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++;
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 I see. Thanks for reply and the fix.