From patchwork Fri Jun 28 17:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1527 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D59C861D17 for ; Fri, 28 Jun 2019 19:00:46 +0200 (CEST) X-Halon-ID: 3d9be8eb-99c6-11e9-8601-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [145.14.112.32]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 3d9be8eb-99c6-11e9-8601-0050569116f7; Fri, 28 Jun 2019 19:00:35 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 28 Jun 2019 19:00:39 +0200 Message-Id: <20190628170039.29659-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Fix variable-sized object initialization X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2019 17:00:47 -0000 Compiling with clang renders errors as a variable-sized arrays are not allowed to be initialized. Solve this by using memset() for v4l2Ctrls which is the only one of the two arrays that needs to be zeroed. ../../src/libcamera/v4l2_device.cpp:155:37: error: variable-sized object may not be initialized const V4L2ControlInfo *controlInfo[count] = {}; ^~~~~ ../../src/libcamera/v4l2_device.cpp:156:36: error: variable-sized object may not be initialized struct v4l2_ext_control v4l2Ctrls[count] = {}; ^~~~~ ../../src/libcamera/v4l2_device.cpp:227:37: error: variable-sized object may not be initialized const V4L2ControlInfo *controlInfo[count] = {}; ^~~~~ ../../src/libcamera/v4l2_device.cpp:228:36: error: variable-sized object may not be initialized struct v4l2_ext_control v4l2Ctrls[count] = {}; ^~~~~ Fixes: eb068f4e67eedacd ("libcamera: v4l2_device: Implement get and set controls") Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index f1821a7ba162e709..e6395341443ce70a 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -152,8 +152,10 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) if (count == 0) return 0; - const V4L2ControlInfo *controlInfo[count] = {}; - struct v4l2_ext_control v4l2Ctrls[count] = {}; + const V4L2ControlInfo *controlInfo[count]; + struct v4l2_ext_control v4l2Ctrls[count]; + memset(v4l2Ctrls, 0, count * sizeof(v4l2Ctrls[0])); + for (unsigned int i = 0; i < count; ++i) { const V4L2Control *ctrl = ctrls->getByIndex(i); const V4L2ControlInfo *info = getControlInfo(ctrl->id()); @@ -224,8 +226,9 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) if (count == 0) return 0; - const V4L2ControlInfo *controlInfo[count] = {}; - struct v4l2_ext_control v4l2Ctrls[count] = {}; + const V4L2ControlInfo *controlInfo[count]; + struct v4l2_ext_control v4l2Ctrls[count]; + memset(v4l2Ctrls, 0, count * sizeof(v4l2Ctrls[0])); for (unsigned int i = 0; i < count; ++i) { const V4L2Control *ctrl = ctrls->getByIndex(i);