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

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

* fix bug
This commit is contained in:
Dean Lee
2021-02-01 23:22:16 +08:00
committed by GitHub
parent 0328f550bc
commit b06da51892

View File

@@ -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);