From 8203d5570221feb7a14349db65142c600e2545ef Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Wed, 17 Mar 2021 14:22:57 +0100 Subject: [PATCH] AlignedBuffer remove operator() to prevent out of scope usage --- messaging/messaging.hpp | 9 ++++----- messaging/socketmaster.cc | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/messaging/messaging.hpp b/messaging/messaging.hpp index 5490a63..e461f06 100644 --- a/messaging/messaging.hpp +++ b/messaging/messaging.hpp @@ -123,9 +123,7 @@ private: class AlignedBuffer { public: - AlignedBuffer() = default; - AlignedBuffer(const char *data, const size_t size) { get(data, size); } - kj::ArrayPtr get(const char *data, const size_t size) { + kj::ArrayPtr align(const char *data, const size_t size) { words_size = size / sizeof(capnp::word) + 1; if (aligned_buf.size() < words_size) { aligned_buf = kj::heapArray(words_size < 512 ? 512 : words_size); @@ -133,8 +131,9 @@ public: memcpy(aligned_buf.begin(), data, size); return aligned_buf.slice(0, words_size); } - inline kj::ArrayPtr get(Message *m) { return get(m->getData(), m->getSize()); } - inline operator kj::ArrayPtr() { return aligned_buf.slice(0, words_size); } + inline kj::ArrayPtr align(Message *m) { + return align(m->getData(), m->getSize()); + } private: kj::Array aligned_buf; size_t words_size; diff --git a/messaging/socketmaster.cc b/messaging/socketmaster.cc index b53f7e5..1240009 100644 --- a/messaging/socketmaster.cc +++ b/messaging/socketmaster.cc @@ -77,7 +77,7 @@ int SubMaster::update(int timeout) { if (m->msg_reader) { m->msg_reader->~FlatArrayMessageReader(); } - m->msg_reader = new (m->allocated_msg_reader) capnp::FlatArrayMessageReader(m->aligned_buf.get(msg)); + m->msg_reader = new (m->allocated_msg_reader) capnp::FlatArrayMessageReader(m->aligned_buf.align(msg)); delete msg; m->event = m->msg_reader->getRoot(); m->updated = true;