[{"id":2055,"web_url":"https://patchwork.libcamera.org/comment/2055/","msgid":"<20190628192502.GA5014@pendragon.ideasonboard.com>","date":"2019-06-28T19:25:02","subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Fix\n\tvariable-sized object initialization","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Fri, Jun 28, 2019 at 07:00:39PM +0200, Niklas Söderlund wrote:\n> Compiling with clang renders errors as a variable-sized arrays are not\n> allowed to be initialized. Solve this by using memset() for v4l2Ctrls\n> which is the only one of the two arrays that needs to be zeroed.\n> \n>     ../../src/libcamera/v4l2_device.cpp:155:37: error: variable-sized object may not be initialized\n>         const V4L2ControlInfo *controlInfo[count] = {};\n>                                            ^~~~~\n>     ../../src/libcamera/v4l2_device.cpp:156:36: error: variable-sized object may not be initialized\n> \t    struct v4l2_ext_control v4l2Ctrls[count] = {};\n> \t\t\t\t\t      ^~~~~\n>     ../../src/libcamera/v4l2_device.cpp:227:37: error: variable-sized object may not be initialized\n> \t    const V4L2ControlInfo *controlInfo[count] = {};\n> \t\t\t\t\t       ^~~~~\n>     ../../src/libcamera/v4l2_device.cpp:228:36: error: variable-sized object may not be initialized\n> \t    struct v4l2_ext_control v4l2Ctrls[count] = {};\n> \t\t\t\t\t      ^~~~~\n> Fixes: eb068f4e67eedacd (\"libcamera: v4l2_device: Implement get and set controls\")\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/v4l2_device.cpp | 11 +++++++----\n>  1 file changed, 7 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index f1821a7ba162e709..e6395341443ce70a 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -152,8 +152,10 @@ int V4L2Device::getControls(V4L2ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>  \n> -\tconst V4L2ControlInfo *controlInfo[count] = {};\n> -\tstruct v4l2_ext_control v4l2Ctrls[count] = {};\n> +\tconst V4L2ControlInfo *controlInfo[count];\n> +\tstruct v4l2_ext_control v4l2Ctrls[count];\n> +\tmemset(v4l2Ctrls, 0, count * sizeof(v4l2Ctrls[0]));\n\nHow about\n\n\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n\n> +\n>  \tfor (unsigned int i = 0; i < count; ++i) {\n>  \t\tconst V4L2Control *ctrl = ctrls->getByIndex(i);\n>  \t\tconst V4L2ControlInfo *info = getControlInfo(ctrl->id());\n> @@ -224,8 +226,9 @@ int V4L2Device::setControls(V4L2ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>  \n> -\tconst V4L2ControlInfo *controlInfo[count] = {};\n> -\tstruct v4l2_ext_control v4l2Ctrls[count] = {};\n> +\tconst V4L2ControlInfo *controlInfo[count];\n> +\tstruct v4l2_ext_control v4l2Ctrls[count];\n> +\tmemset(v4l2Ctrls, 0, count * sizeof(v4l2Ctrls[0]));\n\nAnd here too.\n\nIf that works,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  \tfor (unsigned int i = 0; i < count; ++i) {\n>  \t\tconst V4L2Control *ctrl = ctrls->getByIndex(i);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A97CA61D17\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2019 21:25:21 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3738E2C6;\n\tFri, 28 Jun 2019 21:25:21 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561749921;\n\tbh=01ZywqITiqDL4YY4nK0qbodT43x+sWD1hgQE8EU02EQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DTdVBf+xQSxhkvFZuLFU3jPrJztt+Pw4X+CyYVTouxPahjb9jfYuDgjxeL2+gTN6U\n\teDLJEtLoPS7W6LqeiX8NwY2FNFtpdh9+InXzQ51NBiojboe1RDv3diTGKdle0qXuK4\n\tKdbMUfsXOV5pXqMItzwonNUR5PEt+8Xh439Goe+4=","Date":"Fri, 28 Jun 2019 22:25:02 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190628192502.GA5014@pendragon.ideasonboard.com>","References":"<20190628170039.29659-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190628170039.29659-1-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Fix\n\tvariable-sized object initialization","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 28 Jun 2019 19:25:21 -0000"}}]