[{"id":26847,"web_url":"https://patchwork.libcamera.org/comment/26847/","msgid":"<20230405024734.GE9915@pendragon.ideasonboard.com>","date":"2023-04-05T02:47:34","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Mattijs,\n\nThank you for the patch.\n\nOn Tue, Apr 04, 2023 at 06:11:16PM +0200, Mattijs Korpershoek via libcamera-devel wrote:\n> It's possible to construct a Camera with an unsafe controlInfo_.\n> This is the case in the Simple pipeline, where the camera controls are\n> not populated.\n> \n> With Simple, if we attempt to set a Control, we end up with a segfault\n> because the default constructor for ControlInfoMap doesn't\n> intialized idmap_ which is initialized at class declaration time as\n> \n>   const ControlIdMap *idmap_ = nullptr;\n> \n> Add some safeguards in ControlInfoMap to handle this case.\n> \n> Link: http://codepad.org/CiLLcPNW\n> Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> I have build-tested this against master and functionally tested on a\n> v0.0.4 android integration branch.\n> \n> I've tested that i'm able to do a camera preview even when the\n> ScalerCrop control is unavailble.\n> \n> Note that Jacopo already discussed alternative implementation by making\n> idmap_ an instance instead of a pointer, but that seemed not a good idea\n> either:\n> \n> https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> ---\n>  src/libcamera/controls.cpp | 16 ++++++++++++++++\n>  1 file changed, 16 insertions(+)\n> \n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 6dbf9b348709..b808116c01e5 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n>  \n>  bool ControlInfoMap::validate()\n>  {\n> +\tif (!idmap_)\n> +\t\treturn false;\n> +\n>  \tfor (const auto &ctrl : *this) {\n>  \t\tconst ControlId *id = ctrl.first;\n>  \t\tauto it = idmap_->find(id->id());\n> @@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n>   */\n>  ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>  {\n> +\tASSERT(idmap_);\n> +\n>  \treturn at(idmap_->at(id));\n>  }\n>  \n> @@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>   */\n>  const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>  {\n> +\tASSERT(idmap_);\n> +\n>  \treturn at(idmap_->at(id));\n>  }\n>  \n> @@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>   */\n>  ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>  {\n> +\tif (!idmap_)\n> +\t\treturn 0;\n> +\n>  \t/*\n>  \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n>  \t * entries, we can thus just count the matching entries in idmap to\n> @@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>   */\n>  ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>  {\n> +\tif (!idmap_)\n> +\t\treturn end();\n> +\n>  \tauto iter = idmap_->find(id);\n>  \tif (iter == idmap_->end())\n>  \t\treturn end();\n> @@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>   */\n>  ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n>  {\n> +\tif (!idmap_)\n> +\t\treturn end();\n> +\n>  \tauto iter = idmap_->find(id);\n>  \tif (iter == idmap_->end())\n>  \t\treturn end();\n> \n> ---\n> base-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\n> change-id: 20230404-guard-idmap-1d95f2100aca","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 82A37C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 02:47:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BB76E6274B;\n\tWed,  5 Apr 2023 04:47:30 +0200 (CEST)","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 A627361EC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 04:47:28 +0200 (CEST)","from pendragon.ideasonboard.com (fp76f193f3.tkyc206.ap.nuro.jp\n\t[118.241.147.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 63579905;\n\tWed,  5 Apr 2023 04:47:26 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680662850;\n\tbh=Q/APioe2V16Yq7CjyQQQBEuzm+H7SEYmSOibjsR0OoU=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=iQoVao4qvRUj635z/JhbTrxZqkt+hRbKLs5P3g3nT/DaMaTldabWrx517kFgKKMdS\n\t+WzLScNMRyn2ozUZnYZaTNcQDcsXYT7g5aMQMMO6s5uN1opYgbqkZqKPUjng023ilG\n\tVJBL3Rwvg+3Fnqj+lz50pOsVm6WlScFpBeMNl0bgeFGXPcbo4Hh0ZhYyQ4hAht6Ls2\n\tnwDovYrdUgHHmUgkrobsYiHTy67JtN457qYJUamdpAwpzSW9nchUQDapvNqLIzI4GU\n\tNKZEW+aKW4EUx+aXwwFtEBPFkAummaVS2fpP4MS3s5xcTTYjjumRi5PxKTVLQ+eUC+\n\tTug8q6yqFTbBA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680662848;\n\tbh=Q/APioe2V16Yq7CjyQQQBEuzm+H7SEYmSOibjsR0OoU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OMmyXSBcI7+E7T+hpaZ/jEWWxowNA1PtCeSPcT2Fhl1CWZRdV8dtAXVPqk1KQgEzZ\n\tUPnhE/WeMkcnCPvVKhs3qmWyGokZ8zflBBmd434m1csgN1+pjkWylnwNbxQMz8CHT7\n\tbpsikfzpxicQqcJsKAZl1ICOxXCpCxDK9aq8So+Q="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OMmyXSBc\"; dkim-atps=neutral","Date":"Wed, 5 Apr 2023 05:47:34 +0300","To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Message-ID":"<20230405024734.GE9915@pendragon.ideasonboard.com>","References":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26848,"web_url":"https://patchwork.libcamera.org/comment/26848/","msgid":"<20230405024944.GF9915@pendragon.ideasonboard.com>","date":"2023-04-05T02:49:44","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Apr 05, 2023 at 05:47:41AM +0300, Laurent Pinchart wrote:\n> Hi Mattijs,\n> \n> Thank you for the patch.\n> \n> On Tue, Apr 04, 2023 at 06:11:16PM +0200, Mattijs Korpershoek via libcamera-devel wrote:\n> > It's possible to construct a Camera with an unsafe controlInfo_.\n> > This is the case in the Simple pipeline, where the camera controls are\n> > not populated.\n> > \n> > With Simple, if we attempt to set a Control, we end up with a segfault\n> > because the default constructor for ControlInfoMap doesn't\n> > intialized idmap_ which is initialized at class declaration time as\n> > \n> >   const ControlIdMap *idmap_ = nullptr;\n> > \n> > Add some safeguards in ControlInfoMap to handle this case.\n> > \n> > Link: http://codepad.org/CiLLcPNW\n> > Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> > Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nActually, maybe I ask you to extend the ControlInfoMap unit test to\ncatch the issue ? The test should crash without this patch, and pass\nwith it. This can be done in a separate patch.\n\n> > ---\n> > I have build-tested this against master and functionally tested on a\n> > v0.0.4 android integration branch.\n> > \n> > I've tested that i'm able to do a camera preview even when the\n> > ScalerCrop control is unavailble.\n> > \n> > Note that Jacopo already discussed alternative implementation by making\n> > idmap_ an instance instead of a pointer, but that seemed not a good idea\n> > either:\n> > \n> > https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> > ---\n> >  src/libcamera/controls.cpp | 16 ++++++++++++++++\n> >  1 file changed, 16 insertions(+)\n> > \n> > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> > index 6dbf9b348709..b808116c01e5 100644\n> > --- a/src/libcamera/controls.cpp\n> > +++ b/src/libcamera/controls.cpp\n> > @@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n> >  \n> >  bool ControlInfoMap::validate()\n> >  {\n> > +\tif (!idmap_)\n> > +\t\treturn false;\n> > +\n> >  \tfor (const auto &ctrl : *this) {\n> >  \t\tconst ControlId *id = ctrl.first;\n> >  \t\tauto it = idmap_->find(id->id());\n> > @@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n> >   */\n> >  ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n> >  {\n> > +\tASSERT(idmap_);\n> > +\n> >  \treturn at(idmap_->at(id));\n> >  }\n> >  \n> > @@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n> >   */\n> >  const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n> >  {\n> > +\tASSERT(idmap_);\n> > +\n> >  \treturn at(idmap_->at(id));\n> >  }\n> >  \n> > @@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n> >   */\n> >  ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n> >  {\n> > +\tif (!idmap_)\n> > +\t\treturn 0;\n> > +\n> >  \t/*\n> >  \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n> >  \t * entries, we can thus just count the matching entries in idmap to\n> > @@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n> >   */\n> >  ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n> >  {\n> > +\tif (!idmap_)\n> > +\t\treturn end();\n> > +\n> >  \tauto iter = idmap_->find(id);\n> >  \tif (iter == idmap_->end())\n> >  \t\treturn end();\n> > @@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n> >   */\n> >  ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n> >  {\n> > +\tif (!idmap_)\n> > +\t\treturn end();\n> > +\n> >  \tauto iter = idmap_->find(id);\n> >  \tif (iter == idmap_->end())\n> >  \t\treturn end();\n> > \n> > ---\n> > base-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\n> > change-id: 20230404-guard-idmap-1d95f2100aca","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 029DEC326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 02:49:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7058B62761;\n\tWed,  5 Apr 2023 04:49:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 157DF61EC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 04:49:38 +0200 (CEST)","from pendragon.ideasonboard.com (fp76f193f3.tkyc206.ap.nuro.jp\n\t[118.241.147.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D254905;\n\tWed,  5 Apr 2023 04:49:36 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680662979;\n\tbh=WSrlrMA6q16gQbckP1CCuwrt6VbyFx9ZVEvOSJ/EmkA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=SNiVh5TRCDceEPSPET8xAJYOdwRCM+T3TNEkzph0PhspxkX0n7AW5eWxvrd1sdr2W\n\tWN2IMXLWNdThRUDDT3wTmf8SdVkvbErHe6ZImAc4nXUckZ6rR4OpOz/qXaC/uUyaGA\n\tUt6l2V0A4FWnVPdPBZPqSSxhNlgf0C31nj7JB4zH3Yx16sZeDprWza7KAFq3kIk/+B\n\ta2rZ1IGYeF2IjqhFSa5HO5w+rYhQrGGF3OjFx2cAXus2EMul432iRzZ5aVzFXCk722\n\te8/Sd34S1wOtzNiUiI5LaZJ19MnaF273hF6cIZMYGVy5Nj1QfS31lnV7u60On2x1rZ\n\tvqmO2/Qa9Rj5g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680662977;\n\tbh=WSrlrMA6q16gQbckP1CCuwrt6VbyFx9ZVEvOSJ/EmkA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=FjE8PeC0inZG7X2eJseO/yt8oDfA/Q6smrz0MOPRFxLUEZcO1zqJ8ovPYm8JPakwk\n\t//EyRHQuaw0Lk1c+wk+0AhNI+vVD3KB+jH0jW3ScDNQw/nKvtozhq+i6TDLPCzogNo\n\t9jZVeIGVOSjodyRyLUfd6UzwB8jVNUlhykD3DKSY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"FjE8PeC0\"; dkim-atps=neutral","Date":"Wed, 5 Apr 2023 05:49:44 +0300","To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Message-ID":"<20230405024944.GF9915@pendragon.ideasonboard.com>","References":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>\n\t<20230405024734.GE9915@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230405024734.GE9915@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26857,"web_url":"https://patchwork.libcamera.org/comment/26857/","msgid":"<87jzyqq0uh.fsf@baylibre.com>","date":"2023-04-05T06:50:30","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","submitter":{"id":153,"url":"https://patchwork.libcamera.org/api/people/153/","name":"Mattijs Korpershoek","email":"mkorpershoek@baylibre.com"},"content":"Hi Laurent,\n\nThank you for your review.\n\nOn mer., avril 05, 2023 at 05:49, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:\n\n> On Wed, Apr 05, 2023 at 05:47:41AM +0300, Laurent Pinchart wrote:\n>> Hi Mattijs,\n>> \n>> Thank you for the patch.\n>> \n>> On Tue, Apr 04, 2023 at 06:11:16PM +0200, Mattijs Korpershoek via libcamera-devel wrote:\n>> > It's possible to construct a Camera with an unsafe controlInfo_.\n>> > This is the case in the Simple pipeline, where the camera controls are\n>> > not populated.\n>> > \n>> > With Simple, if we attempt to set a Control, we end up with a segfault\n>> > because the default constructor for ControlInfoMap doesn't\n>> > intialized idmap_ which is initialized at class declaration time as\n>> > \n>> >   const ControlIdMap *idmap_ = nullptr;\n>> > \n>> > Add some safeguards in ControlInfoMap to handle this case.\n>> > \n>> > Link: http://codepad.org/CiLLcPNW\n>> > Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n>> > Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>> > Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n>> \n>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> Actually, maybe I ask you to extend the ControlInfoMap unit test to\n> catch the issue ? The test should crash without this patch, and pass\n> with it. This can be done in a separate patch.\n\nYes, no problem, I will send a V2 extending the ControlInfoMap unit test\nin a separate patch.\n\n>\n>> > ---\n>> > I have build-tested this against master and functionally tested on a\n>> > v0.0.4 android integration branch.\n>> > \n>> > I've tested that i'm able to do a camera preview even when the\n>> > ScalerCrop control is unavailble.\n>> > \n>> > Note that Jacopo already discussed alternative implementation by making\n>> > idmap_ an instance instead of a pointer, but that seemed not a good idea\n>> > either:\n>> > \n>> > https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n>> > ---\n>> >  src/libcamera/controls.cpp | 16 ++++++++++++++++\n>> >  1 file changed, 16 insertions(+)\n>> > \n>> > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n>> > index 6dbf9b348709..b808116c01e5 100644\n>> > --- a/src/libcamera/controls.cpp\n>> > +++ b/src/libcamera/controls.cpp\n>> > @@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n>> >  \n>> >  bool ControlInfoMap::validate()\n>> >  {\n>> > +\tif (!idmap_)\n>> > +\t\treturn false;\n>> > +\n>> >  \tfor (const auto &ctrl : *this) {\n>> >  \t\tconst ControlId *id = ctrl.first;\n>> >  \t\tauto it = idmap_->find(id->id());\n>> > @@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n>> >   */\n>> >  ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>> >  {\n>> > +\tASSERT(idmap_);\n>> > +\n>> >  \treturn at(idmap_->at(id));\n>> >  }\n>> >  \n>> > @@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>> >   */\n>> >  const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>> >  {\n>> > +\tASSERT(idmap_);\n>> > +\n>> >  \treturn at(idmap_->at(id));\n>> >  }\n>> >  \n>> > @@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>> >   */\n>> >  ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>> >  {\n>> > +\tif (!idmap_)\n>> > +\t\treturn 0;\n>> > +\n>> >  \t/*\n>> >  \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n>> >  \t * entries, we can thus just count the matching entries in idmap to\n>> > @@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>> >   */\n>> >  ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>> >  {\n>> > +\tif (!idmap_)\n>> > +\t\treturn end();\n>> > +\n>> >  \tauto iter = idmap_->find(id);\n>> >  \tif (iter == idmap_->end())\n>> >  \t\treturn end();\n>> > @@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>> >   */\n>> >  ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n>> >  {\n>> > +\tif (!idmap_)\n>> > +\t\treturn end();\n>> > +\n>> >  \tauto iter = idmap_->find(id);\n>> >  \tif (iter == idmap_->end())\n>> >  \t\treturn end();\n>> > \n>> > ---\n>> > base-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\n>> > change-id: 20230404-guard-idmap-1d95f2100aca\n>\n> -- \n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 28F15BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 06:50:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D069F62761;\n\tWed,  5 Apr 2023 08:50:33 +0200 (CEST)","from mail-wm1-x333.google.com (mail-wm1-x333.google.com\n\t[IPv6:2a00:1450:4864:20::333])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F99F61EC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 08:50:32 +0200 (CEST)","by mail-wm1-x333.google.com with SMTP id\n\tm6-20020a05600c3b0600b003ee6e324b19so21348349wms.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 04 Apr 2023 23:50:32 -0700 (PDT)","from localhost ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1])\n\tby smtp.gmail.com with ESMTPSA id\n\th18-20020a05600c315200b003ef6708bc1esm1118120wmo.43.2023.04.04.23.50.31\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 04 Apr 2023 23:50:31 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680677433;\n\tbh=qMXPk7PQ4/Qj4g9OdNFOkMRpYU71WeAFRWdObZirkm0=;\n\th=To:In-Reply-To:References:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=hcy8KZjQ50fZbAZBIAkt4cxCZwrWVdn4mAq/hVJ8XU0RUnb2dfL38EhDNzccYL1wT\n\tcNmsjbRnskZawg5mmZtbRM2i1KvMJicKS+2glTxQfA186Q8BZcFvWxxhoyc0KdWgk3\n\t+UtNuMbXYd2uacPIaCZv1VUcQkRkrRfikBmT4pwBrbCgviL3kMDTlvA1M0yoZgUPUu\n\tuugPjz5rnSRlCUXBCmQOHPup5bfRFIky3luCqHfTi4dIKgR3QEOt/uOKpLmlAbCtdM\n\tijqsSESidOHQvuFjK3pF3IXcGoAFLs0ODDQg2eCc09v9xWjI88lbLYjZACGdSkIPY5\n\tlK7i7LlP8GYPA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1680677432;\n\th=mime-version:message-id:date:references:in-reply-to:subject:cc:to\n\t:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=DwC2mTLUsVLM6EAzZ6Sx+LO8hgj/eq13Jfs5VIAfLvc=;\n\tb=yM2703AP+Nh31JlH4GK9kZiY28fO53RRaaFTt6C/Ft2WvUeXaIZ5WGaUxWWW5bPhKG\n\tqwW64poemA8HzHVRVkM8n3HjuQSmXBzNXzgAzHXe9eXtSXM7kJ8iYBgYyyWRq8G5iqzI\n\tr3PfTB28IO/82P2pw2oorpxNz61ahYP844V0DJhAMdMlIPqifCm9zALqE+pHvwV5404e\n\txDsqs4km4Dbjc6TTyBOs7xlh5rvAqtAjcKdeoEIWrEDvf4Ntaais2Z+ahxr1VIkEhaHY\n\tWwEVuE12CqzRc21PGO3UDMi8rWqtqLbvAlP1AQBpyKDkR36jDIYtYErAZaJeBlLj1Nv0\n\tOWdg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20210112.gappssmtp.com\n\theader.i=@baylibre-com.20210112.gappssmtp.com header.b=\"yM2703AP\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1680677432;\n\th=mime-version:message-id:date:references:in-reply-to:subject:cc:to\n\t:from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; \n\tbh=DwC2mTLUsVLM6EAzZ6Sx+LO8hgj/eq13Jfs5VIAfLvc=;\n\tb=WHAQhCu03HZDbb9rC2j8ELgL0hm49XjrrbJ2QycThpcyoTJTl2Z4LP6m744HJTxSzC\n\teOT6mHgkC0OfRBKqhMmN6cjVzRe9vGzNjUkrynQJktxon/e9DkdHYijC2qGHFlMeVwHv\n\telZvjKs1M9kV3AGg/cl/jxbWOk9LQOh4d6jmOUSnsRnU3Ty56uevurEFpQ+73Dt89I3Y\n\t9e9x+x3I7H1KTVPK2Q8U5i9cLk+revmjsAmJbQvR83dTauRkg0JIN9/VR+MSMjsOUZuG\n\ttRZUKQbsymRZN38WAYBQuuDtX68qp0KSiMZtS+YnQ+KY0KAOf9+NqcTV/tTxG0vBNsRX\n\tOOzw==","X-Gm-Message-State":"AAQBX9fPa9fN89y9j5n0fXiPS/0H1Eu5IrAtiWQE3tUkYosXnmwPoLFR\n\tYGMf5kehWMC/mAoTzK+6ncYyNg==","X-Google-Smtp-Source":"AKy350atQd22e5UINdYyY76DfQnZtDV8Hwb+K8h8KbGs9xxuz3AJta+usRmvhCpVCiYDxWiqyRFYfA==","X-Received":"by 2002:a1c:6a04:0:b0:3ee:da1:1346 with SMTP id\n\tf4-20020a1c6a04000000b003ee0da11346mr3746870wmc.36.1680677432019; \n\tTue, 04 Apr 2023 23:50:32 -0700 (PDT)","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","In-Reply-To":"<20230405024944.GF9915@pendragon.ideasonboard.com>","References":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>\n\t<20230405024734.GE9915@pendragon.ideasonboard.com>\n\t<20230405024944.GF9915@pendragon.ideasonboard.com>","Date":"Wed, 05 Apr 2023 08:50:30 +0200","Message-ID":"<87jzyqq0uh.fsf@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Mattijs Korpershoek via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26858,"web_url":"https://patchwork.libcamera.org/comment/26858/","msgid":"<20230405080151.px2bcuppvsibwuii@uno.localdomain>","date":"2023-04-05T08:01:51","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hello Mattijs\n\nOn Tue, Apr 04, 2023 at 06:11:16PM +0200, Mattijs Korpershoek via libcamera-devel wrote:\n> It's possible to construct a Camera with an unsafe controlInfo_.\n> This is the case in the Simple pipeline, where the camera controls are\n> not populated.\n>\n> With Simple, if we attempt to set a Control, we end up with a segfault\n> because the default constructor for ControlInfoMap doesn't\n> intialized idmap_ which is initialized at class declaration time as\n>\n>   const ControlIdMap *idmap_ = nullptr;\n>\n> Add some safeguards in ControlInfoMap to handle this case.\n>\n> Link: http://codepad.org/CiLLcPNW\n\nThis won't stay here forever I presume, I'm not sure it should be in\nthe git history. A minor detail, can be removed when applying\n\n> Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n   j\n\n> ---\n> I have build-tested this against master and functionally tested on a\n> v0.0.4 android integration branch.\n>\n> I've tested that i'm able to do a camera preview even when the\n> ScalerCrop control is unavailble.\n>\n> Note that Jacopo already discussed alternative implementation by making\n> idmap_ an instance instead of a pointer, but that seemed not a good idea\n> either:\n>\n> https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n> ---\n>  src/libcamera/controls.cpp | 16 ++++++++++++++++\n>  1 file changed, 16 insertions(+)\n>\n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 6dbf9b348709..b808116c01e5 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n>\n>  bool ControlInfoMap::validate()\n>  {\n> +\tif (!idmap_)\n> +\t\treturn false;\n> +\n>  \tfor (const auto &ctrl : *this) {\n>  \t\tconst ControlId *id = ctrl.first;\n>  \t\tauto it = idmap_->find(id->id());\n> @@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n>   */\n>  ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>  {\n> +\tASSERT(idmap_);\n> +\n>  \treturn at(idmap_->at(id));\n>  }\n>\n> @@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>   */\n>  const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>  {\n> +\tASSERT(idmap_);\n> +\n>  \treturn at(idmap_->at(id));\n>  }\n>\n> @@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>   */\n>  ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>  {\n> +\tif (!idmap_)\n> +\t\treturn 0;\n> +\n>  \t/*\n>  \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n>  \t * entries, we can thus just count the matching entries in idmap to\n> @@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>   */\n>  ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>  {\n> +\tif (!idmap_)\n> +\t\treturn end();\n> +\n>  \tauto iter = idmap_->find(id);\n>  \tif (iter == idmap_->end())\n>  \t\treturn end();\n> @@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>   */\n>  ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n>  {\n> +\tif (!idmap_)\n> +\t\treturn end();\n> +\n>  \tauto iter = idmap_->find(id);\n>  \tif (iter == idmap_->end())\n>  \t\treturn end();\n>\n> ---\n> base-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\n> change-id: 20230404-guard-idmap-1d95f2100aca\n>\n> Best regards,\n> --\n> Mattijs Korpershoek <mkorpershoek@baylibre.com>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 58AF9C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 08:01:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 813C5626E2;\n\tWed,  5 Apr 2023 10:01:56 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1DA2961EC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 10:01:55 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2001:b07:5d2e:52c9:1cf0:b3bc:c785:4625])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A0000128D;\n\tWed,  5 Apr 2023 10:01:54 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680681716;\n\tbh=h+CK+95bPrXBOsszianB26L+TMccwBHgwJEFSGgkgoY=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=13slEDHfSmiQ4GJJDn2lDXNoysX4H1PkxYa3osqBD4nh0b2j1mQL0/Xcy80+OfEC7\n\tDLqS3VX2v+uRsjcG2zI5ko2EghN2U0kpptbweESQE+rBHAvsNycghNMmeERwyuYlG5\n\th+e4fafTi6cIAoy1TyTvtza4Cp4nxQoe9YNJHaP2VTmCUVQ2xpBrD6BO3clpZRa6sy\n\tSQLLB49VgMtPC86H/56qvgqP9tZZ5LUgqpMzUCJOKS4g3nQu/l0GQEvgW8dEeWqmNF\n\tzUN+7ZZ/hu7t/4rg2Tu+d7do9MIKt1V8V8+XNQkjBuQs29ja8LqXQBn0cNLU5S8kke\n\tF3C+rMWbPf/+A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680681714;\n\tbh=h+CK+95bPrXBOsszianB26L+TMccwBHgwJEFSGgkgoY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gPIJe4dRCEijOjtW3zaq07GIN51sFmF0HnEsmY65sv51g/E1Kz2pUrGDlGNOB91i5\n\tLrrPrvzt03FOXZPzbvyJJ2K+jkvRkGPLpquI8hLEMZl25vaMecKdbzwH/xMdmFXNiw\n\tpMMkKn85GKC1+OtXfYdnhCtIR2SkR1lcIiOmAMj4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"gPIJe4dR\"; dkim-atps=neutral","Date":"Wed, 5 Apr 2023 10:01:51 +0200","To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Message-ID":"<20230405080151.px2bcuppvsibwuii@uno.localdomain>","References":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26859,"web_url":"https://patchwork.libcamera.org/comment/26859/","msgid":"<87v8iarbvz.fsf@baylibre.com>","date":"2023-04-05T08:06:40","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","submitter":{"id":153,"url":"https://patchwork.libcamera.org/api/people/153/","name":"Mattijs Korpershoek","email":"mkorpershoek@baylibre.com"},"content":"Hi Jacopo,\n\nThank you for your review.\n\nOn mer., avril 05, 2023 at 10:01, Jacopo Mondi <jacopo.mondi@ideasonboard.com> wrote:\n\n> Hello Mattijs\n>\n> On Tue, Apr 04, 2023 at 06:11:16PM +0200, Mattijs Korpershoek via libcamera-devel wrote:\n>> It's possible to construct a Camera with an unsafe controlInfo_.\n>> This is the case in the Simple pipeline, where the camera controls are\n>> not populated.\n>>\n>> With Simple, if we attempt to set a Control, we end up with a segfault\n>> because the default constructor for ControlInfoMap doesn't\n>> intialized idmap_ which is initialized at class declaration time as\n>>\n>>   const ControlIdMap *idmap_ = nullptr;\n>>\n>> Add some safeguards in ControlInfoMap to handle this case.\n>>\n>> Link: http://codepad.org/CiLLcPNW\n>\n> This won't stay here forever I presume, I'm not sure it should be in\n> the git history. A minor detail, can be removed when applying\n\nSince I'm spinning up a v2 with an added unit test, I will move this\ncodepad link to the cover letter instead.\n\n>\n>> Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n>> Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n>\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>\n> Thanks\n>    j\n>\n>> ---\n>> I have build-tested this against master and functionally tested on a\n>> v0.0.4 android integration branch.\n>>\n>> I've tested that i'm able to do a camera preview even when the\n>> ScalerCrop control is unavailble.\n>>\n>> Note that Jacopo already discussed alternative implementation by making\n>> idmap_ an instance instead of a pointer, but that seemed not a good idea\n>> either:\n>>\n>> https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n>> ---\n>>  src/libcamera/controls.cpp | 16 ++++++++++++++++\n>>  1 file changed, 16 insertions(+)\n>>\n>> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n>> index 6dbf9b348709..b808116c01e5 100644\n>> --- a/src/libcamera/controls.cpp\n>> +++ b/src/libcamera/controls.cpp\n>> @@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n>>\n>>  bool ControlInfoMap::validate()\n>>  {\n>> +\tif (!idmap_)\n>> +\t\treturn false;\n>> +\n>>  \tfor (const auto &ctrl : *this) {\n>>  \t\tconst ControlId *id = ctrl.first;\n>>  \t\tauto it = idmap_->find(id->id());\n>> @@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n>>   */\n>>  ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>>  {\n>> +\tASSERT(idmap_);\n>> +\n>>  \treturn at(idmap_->at(id));\n>>  }\n>>\n>> @@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n>>   */\n>>  const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>>  {\n>> +\tASSERT(idmap_);\n>> +\n>>  \treturn at(idmap_->at(id));\n>>  }\n>>\n>> @@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n>>   */\n>>  ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>>  {\n>> +\tif (!idmap_)\n>> +\t\treturn 0;\n>> +\n>>  \t/*\n>>  \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n>>  \t * entries, we can thus just count the matching entries in idmap to\n>> @@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n>>   */\n>>  ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>>  {\n>> +\tif (!idmap_)\n>> +\t\treturn end();\n>> +\n>>  \tauto iter = idmap_->find(id);\n>>  \tif (iter == idmap_->end())\n>>  \t\treturn end();\n>> @@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n>>   */\n>>  ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n>>  {\n>> +\tif (!idmap_)\n>> +\t\treturn end();\n>> +\n>>  \tauto iter = idmap_->find(id);\n>>  \tif (iter == idmap_->end())\n>>  \t\treturn end();\n>>\n>> ---\n>> base-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\n>> change-id: 20230404-guard-idmap-1d95f2100aca\n>>\n>> Best regards,\n>> --\n>> Mattijs Korpershoek <mkorpershoek@baylibre.com>\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id EB9ECBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Apr 2023 08:06:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C6CD62754;\n\tWed,  5 Apr 2023 10:06:43 +0200 (CEST)","from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com\n\t[IPv6:2a00:1450:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AD15E61EC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Apr 2023 10:06:41 +0200 (CEST)","by mail-wr1-x42c.google.com with SMTP id v1so35282200wrv.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 05 Apr 2023 01:06:41 -0700 (PDT)","from localhost ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1])\n\tby smtp.gmail.com with ESMTPSA id\n\tq11-20020a5d574b000000b002c54c92e125sm14327087wrw.46.2023.04.05.01.06.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 05 Apr 2023 01:06:40 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680682003;\n\tbh=e11UZsMwll5bwCiPkmiAvyytFE7F34/Mfq4UiN8fPU4=;\n\th=To:In-Reply-To:References:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=LuI8/fuhXf6EzrhLnGMShODfYPPiRl7P7ihawCpwmrFf+rzXaAd5nalaCc8/yfTLZ\n\tisWOHseBr2ihCYinjdV5mdL58OGpp7yUujNKh/VHpM/TTXq0O+/T6jS5v3ZcyAOyw6\n\tXSgHYugwnUrPyLZ0uRl2QpRcmDv++jZA4+2J9WrKi3JYV/8qamx+JxSOwiUbiyGPPS\n\th5BsjYSSWxIWLam6DbAMXdoSfEzjiFAGLBwOTZt+1Be2sikK46Ohohtpd3JJwjhxmQ\n\tySC33dE1pqj9yQ+M8kHUz1VKaXOmIeuwJrlUrYWS+Cu58kumkjErJu8lTmWHY/foeE\n\txEJhewszfwvLg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1680682001;\n\th=mime-version:message-id:date:references:in-reply-to:subject:cc:to\n\t:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=b55mi44O1CvftYHIBWoDFo5CMK2rDvPSlSG4P7V0pBk=;\n\tb=o/XT1RejnauaI84AJUp3GScUvH+uW91K8s3yq4nZdii7yn6GCNOWva4WwCTfVVv+TM\n\tzHIEfPkPDDZNOX/N97jkIm1x66UdwLKsxBOi3LCR5T5gun/SFsqzP6bj81h4CsxWEi9V\n\tg9/Ehy5LW+AshSIDYC1VYA4IfiFaBTNHDZ4FISotFlNchYQ1Kx7bD+N2t/dKtyrIVWjC\n\t7nQ8n31iGA6if/PCZ22T8LrcRRD18mm7m9rx5OPRmR3FczsH+W1jtHF+r8nac/xcOStE\n\taNWBRaBTEfiDnbJqVG7B4llAO18p6u2X7/01ad1Z8CZNbz2r4DLBULLPsycamkkYm/OM\n\tYb3Q=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20210112.gappssmtp.com\n\theader.i=@baylibre-com.20210112.gappssmtp.com header.b=\"o/XT1Rej\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1680682001;\n\th=mime-version:message-id:date:references:in-reply-to:subject:cc:to\n\t:from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; \n\tbh=b55mi44O1CvftYHIBWoDFo5CMK2rDvPSlSG4P7V0pBk=;\n\tb=U5mPjptEvAa0dERBtapz0DG6LYtaPeSaCBFfz8Tl7ahB7vMfPojA4+3ZiaYwnyzGqY\n\tdoPgfBgfYoLG1oWQlfR9Y5i0apJ0qCofpzPUr7qu6/cfDLkLJa45V5lXaQVdNMs02nM1\n\tqYBEFjUOf/uDRaKIsmgZTdtP5Na7ZVmuvZ7s/wrkbJTLRio2TUUGAU0sXA5AHwW53clK\n\t7nkYRdRoYXolvS6MzoXoXXRDT2fRxjvYMs3iT81R4ZTWFvvzDanfKapuja9soyho//RU\n\t/V2nLSXuH5PMnpRqVxIURwTu9L4XN/36Y41DOnvOUe8aQ3E6ERwQay6NFQ4ALMCX7TEx\n\t2sDQ==","X-Gm-Message-State":"AAQBX9cqaS/BeZMCKSwgcv/ybdfxgCpvUlRZaUx8f1s8tHkr7UQPUpqZ\n\tyfhYuMVsqlnUJM9kzzCrU00vHg==","X-Google-Smtp-Source":"AKy350aHMYRLsRbCejn0Kt5Cn4q0HFVQxwn6JEyPGmBnG5lZyfHjHHnvEMvFIQzI2Zn/CDM+E+c5/Q==","X-Received":"by 2002:adf:ea84:0:b0:2e6:271:32ea with SMTP id\n\ts4-20020adfea84000000b002e6027132eamr3399697wrm.30.1680682001207; \n\tWed, 05 Apr 2023 01:06:41 -0700 (PDT)","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","In-Reply-To":"<20230405080151.px2bcuppvsibwuii@uno.localdomain>","References":"<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>\n\t<20230405080151.px2bcuppvsibwuii@uno.localdomain>","Date":"Wed, 05 Apr 2023 10:06:40 +0200","Message-ID":"<87v8iarbvz.fsf@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: guard\n\tControlInfoMap against nullptr idmap_","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Mattijs Korpershoek via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]