diff --git a/selfdrive/boardd/pigeon.cc b/selfdrive/boardd/pigeon.cc index 04ad4c5f7e..d5b577b5f8 100644 --- a/selfdrive/boardd/pigeon.cc +++ b/selfdrive/boardd/pigeon.cc @@ -105,11 +105,11 @@ void PandaPigeon::send(const std::string &s) { std::string PandaPigeon::receive() { std::string r; - - while (true){ - unsigned char dat[0x40]; + r.reserve(0x1000 + 0x40); + unsigned char dat[0x40]; + while (r.length() < 0x1000){ int len = panda->usb_read(0xe0, 1, 0, dat, sizeof(dat)); - if (len <= 0 || r.length() > 0x1000) break; + if (len <= 0) break; r.append((char*)dat, len); } @@ -190,13 +190,13 @@ void TTYPigeon::send(const std::string &s) { std::string TTYPigeon::receive() { std::string r; - - while (true){ - char dat[0x40]; + r.reserve(0x1000 + 0x40); + char dat[0x40]; + while (r.length() < 0x1000){ int len = read(pigeon_tty_fd, dat, sizeof(dat)); if(len < 0) { handle_tty_issue(len, __func__); - } else if (len == 0 || r.length() > 0x1000){ + } else if (len == 0){ break; } else { r.append(dat, len);