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 --- include/libcamera/internal/v4l2_videodevice.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include/libcamera') diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 53f6a2d5..dcb9654a 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ #define __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ +#include #include #include #include @@ -153,14 +154,16 @@ private: class V4L2DeviceFormat { public: + struct Plane { + uint32_t size = 0; + uint32_t bpl = 0; + }; + V4L2PixelFormat fourcc; Size size; - struct { - uint32_t size; - uint32_t bpl; - } planes[3]; - unsigned int planesCount; + std::array planes; + unsigned int planesCount = 0; const std::string toString() const; }; -- cgit v1.2.1