Pigeon::receive: reserve 4kb+64b for std::string (#19951)

* receive: reserve 4kb+64b for std::string

* fix bug
old-commit-hash: b06da51892
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent d1ba59fd0a
commit 6a04e4c06a
  1. 16
      selfdrive/boardd/pigeon.cc

@ -105,11 +105,11 @@ void PandaPigeon::send(const std::string &s) {
std::string PandaPigeon::receive() { std::string PandaPigeon::receive() {
std::string r; std::string r;
r.reserve(0x1000 + 0x40);
while (true){ unsigned char dat[0x40];
unsigned char dat[0x40]; while (r.length() < 0x1000){
int len = panda->usb_read(0xe0, 1, 0, dat, sizeof(dat)); 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); r.append((char*)dat, len);
} }
@ -190,13 +190,13 @@ void TTYPigeon::send(const std::string &s) {
std::string TTYPigeon::receive() { std::string TTYPigeon::receive() {
std::string r; std::string r;
r.reserve(0x1000 + 0x40);
while (true){ char dat[0x40];
char dat[0x40]; while (r.length() < 0x1000){
int len = read(pigeon_tty_fd, dat, sizeof(dat)); int len = read(pigeon_tty_fd, dat, sizeof(dat));
if(len < 0) { if(len < 0) {
handle_tty_issue(len, __func__); handle_tty_issue(len, __func__);
} else if (len == 0 || r.length() > 0x1000){ } else if (len == 0){
break; break;
} else { } else {
r.append(dat, len); r.append(dat, len);

Loading…
Cancel
Save