1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-23 04:04:54 +08:00

fix invalid memory access when eol size >1

This commit is contained in:
chenguojun 2020-04-28 15:11:44 +08:00
parent cbcca7c837
commit 743a1badf3

View File

@ -188,6 +188,7 @@ Serial::readline (string &buffer, size_t size, string eol)
if (bytes_read == 0) {
break; // Timeout occured on reading 1 byte
}
if(read_so_far < eol_len) continue;
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
break; // EOL found
@ -229,6 +230,7 @@ Serial::readlines (size_t size, string eol)
}
break; // Timeout occured on reading 1 byte
}
if(read_so_far < eol_len) continue;
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
// EOL found