From f027059629257841cb1329a9ca576fc7a05c5aa6 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sat, 8 Jun 2024 07:48:37 +0800 Subject: [PATCH] CANParser: fix can data size issue (#799) fix can data size issues Co-authored-by: Shane Smiskol --- can/parser.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/can/parser.cc b/can/parser.cc index 3efa3ee369..39c0876720 100644 --- a/can/parser.cc +++ b/can/parser.cc @@ -236,8 +236,9 @@ void CANParser::UpdateCans(uint64_t nanos, const capnp::List::R // DEBUG("got message with unexpected length: expected %d, got %zu for %d", state_it->second.size, dat.size(), cmsg.getAddress()); // continue; //} - - std::vector data(dat.size(), 0); + // make sure the data_size if not less than state_it->second.size. + size_t data_size = std::max(dat.size(), state_it->second.size); + std::vector data(data_size, 0); memcpy(data.data(), dat.begin(), dat.size()); state_it->second.parse(nanos, data); }