From 2d43b8bcd8571dbce1969fa1fd50c655585f780b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 4 Nov 2020 09:06:43 +0200 Subject: libcamera: v4l2_videodevice: Zero-initialize planes in V4L2DeviceFormat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The V4L2DeviceFormat class doesn't have a default constructor, neither does it specifies default member initializers for the plane-related members. This results in the planes array and planesCount members being uninitialized by default, leading to undefined behaviour if the user of the class doesn't initialize it explicitly. Most users initialize V4L2DeviceFormat instances, but some don't. We could fix them, but that would likely turn into a game of whack-a-mole. As there's no use case for instantiating a large number of V4L2DeviceFormat instances in a performance-critical code path, let's instead add default initializers to avoid future issues. While at it, define a type of the structures containing plane information, and use an std::array. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/v4l2_videodevice.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libcamera/v4l2_videodevice.cpp') diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 36d7d9a0..d07c3530 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -351,6 +351,15 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const * V4L2DeviceFormat::planesCount value. */ +/** + * \struct V4L2DeviceFormat::Plane + * \brief Per-plane memory size information + * \var V4L2DeviceFormat::Plane::size + * \brief The plane total memory size (in bytes) + * \var V4L2DeviceFormat::Plane::bpl + * \brief The plane line stride (in bytes) + */ + /** * \var V4L2DeviceFormat::size * \brief The image size in pixels -- cgit v1.2.1