Patch Detail
Show a patch.
GET /api/1.1/patches/12824/?format=api
{ "id": 12824, "url": "https://patchwork.libcamera.org/api/1.1/patches/12824/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12824/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210707021941.20804-12-laurent.pinchart@ideasonboard.com>", "date": "2021-07-07T02:19:22", "name": "[libcamera-devel,11/30] cam: options: Avoid copies of OptionvValue and KeyValueParser::Options", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "0763bf6e6f2b2ab1424f6b759656a0f7adebc21f", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/12824/mbox/", "series": [ { "id": 2213, "url": "https://patchwork.libcamera.org/api/1.1/series/2213/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2213", "date": "2021-07-07T02:19:12", "name": "Multi-camera support in the cam application", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2213/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12824/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12824/checks/", "tags": {}, "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 B0FFBC3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 7 Jul 2021 02:20:44 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9E15468529;\n\tWed, 7 Jul 2021 04:20:41 +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 879916850C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 7 Jul 2021 04:20:35 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 09385466\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 7 Jul 2021 04:20:34 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"OOeUVSMq\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1625624435;\n\tbh=hmPHGzwAxUE8U1K60Zl1TwCoV+QrKuHJcrle3x6g+Hs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=OOeUVSMqYCYcY6Ojgb+YKqqyS1OOyhUqcvB04ymwMx5snIEpVLsteLDEXTtjexrak\n\t8DAH98u73CakGB+6nBhvDjFlav6saR8JivGaxD3yyryynZ/AdLRSl83hhSbDwbeqt3\n\tiw72q9Knl+StbqTye8BqMDNQDkCjq+y1WNa1DTkM=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 7 Jul 2021 05:19:22 +0300", "Message-Id": "<20210707021941.20804-12-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.31.1", "In-Reply-To": "<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>", "References": "<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 11/30] cam: options: Avoid copies of\n\tOptionvValue and KeyValueParser::Options", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The OptionValue toKeyValues() and toArray() functions return a copy of\nthe values. This is unnecessary, and can cause use-after-free issues\nwhen taking references to the return values. Return references instead\nto optimize the implementation and avoid issues.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/cam/options.cpp | 22 ++++++++++------------\n src/cam/options.h | 4 ++--\n 2 files changed, 12 insertions(+), 14 deletions(-)", "diff": "diff --git a/src/cam/options.cpp b/src/cam/options.cpp\nindex 319fab6143c5..9de3dd77fd15 100644\n--- a/src/cam/options.cpp\n+++ b/src/cam/options.cpp\n@@ -632,27 +632,25 @@ std::string OptionValue::toString() const\n \n /**\n * \\brief Retrieve the value as a key-value list\n- * \\return The option value as a KeyValueParser::Options, or an empty list if\n- * the value type isn't ValueType::ValueKeyValue\n+ *\n+ * The behaviour is undefined if the value type isn't ValueType::ValueKeyValue.\n+ *\n+ * \\return The option value as a KeyValueParser::Options\n */\n-KeyValueParser::Options OptionValue::toKeyValues() const\n+const KeyValueParser::Options &OptionValue::toKeyValues() const\n {\n-\tif (type_ != ValueKeyValue)\n-\t\treturn KeyValueParser::Options();\n-\n \treturn keyValues_;\n }\n \n /**\n * \\brief Retrieve the value as an array\n- * \\return The option value as a std::vector of OptionValue, or an empty vector\n- * if the value type isn't ValueType::ValueArray\n+ *\n+ * The behaviour is undefined if the value type isn't ValueType::ValueArray.\n+ *\n+ * \\return The option value as a std::vector of OptionValue\n */\n-std::vector<OptionValue> OptionValue::toArray() const\n+const std::vector<OptionValue> &OptionValue::toArray() const\n {\n-\tif (type_ != ValueArray)\n-\t\treturn std::vector<OptionValue>{};\n-\n \treturn array_;\n }\n \ndiff --git a/src/cam/options.h b/src/cam/options.h\nindex 210e502a24e1..09cbc8339dd0 100644\n--- a/src/cam/options.h\n+++ b/src/cam/options.h\n@@ -141,8 +141,8 @@ public:\n \n \tint toInteger() const;\n \tstd::string toString() const;\n-\tKeyValueParser::Options toKeyValues() const;\n-\tstd::vector<OptionValue> toArray() const;\n+\tconst KeyValueParser::Options &toKeyValues() const;\n+\tconst std::vector<OptionValue> &toArray() const;\n \n \tconst OptionsParser::Options &children() const;\n \n", "prefixes": [ "libcamera-devel", "11/30" ] }