From patchwork Wed Oct 7 09:22:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 9988 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 354C3BEEDF for ; Wed, 7 Oct 2020 09:23:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF52863C13; Wed, 7 Oct 2020 11:23:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nfnGlh6V"; dkim-atps=neutral Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAD0C6035F for ; Wed, 7 Oct 2020 11:23:22 +0200 (CEST) Received: by mail-lj1-x241.google.com with SMTP id l13so1233729ljg.10 for ; Wed, 07 Oct 2020 02:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4V2i6L2nkUl5kfyEdjUktK9rgnrR+tdhx5llmPlWigg=; b=nfnGlh6VdXRXbU+Dir5r9ecfxYKjPl1D9wZRwggQPlsogxlF6lbQMDX8C28JWIEitn MX85XIUEC4GwBhgK2A4ax2xIVjR8F2MP9AO+CAp3FuArTi+jPVbQceGXY3Eg7HyeGhOV oYtiP9LR+Qp2E3AkUYPV19tL+OYHcvB+IzcGPsrsg5S4H/qspaTOErYL1wyEtX2v67pE UDBPe6Dnrv6x9a7YGJLez7p8TZWeeH/TTU3P7bs9A2RIZm/piuOtqbOjXqUGB9Gobwc0 Yx5fK7tewCLXCJ5mOK1kHF+LVkllhDPKIO4qpt2vgTQtdHwwKmLcVbeUZVjnVpdbcEuy Jvsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=4V2i6L2nkUl5kfyEdjUktK9rgnrR+tdhx5llmPlWigg=; b=prqXwpzA3S+T9lUhOeo2aixatLMfzKZEhk6OLkCq791FULJwp6545nATNAE9LfsMq3 bnj9zy9/XTLYyTYoh1yhqyZDctoU9SweOGV0rq8jkZEIqaZ8Fmp96npzcY0glLg6n4eQ i4FISmqZquah3yhJFtI7D9eM0nvioRGKNGE8cx59ehAMs7+n7YdqgzFkDezVKnAiiQTW cCj/EZNVACj2J1DRFIkxhzuhzBZxZq11CgsvmizcM64fmBa1d6rUpJ7Ca7K1Y/90Vj54 SGLDibVS2BJNTIbaWy1WLtSKBh2VDPOs1VPTUn3uf0YTQhHPtPMjKKWtFjQRGWVzxOL5 gOYQ== X-Gm-Message-State: AOAM530iSJNtlHkfJPwxfcW98lJwsonu/WCjUn9tlx9zDRVLJhiZgDtJ 8THMxn57ny3Hf8MbR74DXoGtptCslxxK9A== X-Google-Smtp-Source: ABdhPJxjLQnY3ydXemTnMvkWPheeQHV2dKncyVIy+Y6A42r8mJNCho4NPICvdjDwTgahqjYCpx4c7Q== X-Received: by 2002:a2e:8942:: with SMTP id b2mr910368ljk.441.1602062601890; Wed, 07 Oct 2020 02:23:21 -0700 (PDT) Received: from deskari.lan (91-152-83-50.elisa-laajakaista.fi. [91.152.83.50]) by smtp.gmail.com with ESMTPSA id n26sm258341ljg.133.2020.10.07.02.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 02:23:21 -0700 (PDT) From: Tomi Valkeinen To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:22:36 +0300 Message-Id: <20201007092239.41704-1-tomi.valkeinen@iki.fi> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] cam: options: fix access to uninit variable X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" operator[] doesn't check if the option exists in the values_ map, so it can return a pointer to location outside the map. Fix by returning an empty OptionValue if the option is not found. Signed-off-by: Tomi Valkeinen Reviewed-by: Kieran Bingham --- src/cam/options.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 77b3cc1..8fc1c42 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -61,7 +61,12 @@ bool OptionsBase::isSet(const T &opt) const template const OptionValue &OptionsBase::operator[](const T &opt) const { - return values_.find(opt)->second; + static const OptionValue s_empty; + + auto it = values_.find(opt); + if (it != values_.end()) + return it->second; + return s_empty; } template