From 3c636755607919bc99b2219683a402660740f0db Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 7 Jul 2021 04:02:07 +0300 Subject: cam: options: Avoid copies of OptionvValue and KeyValueParser::Options The OptionValue toKeyValues() and toArray() functions return a copy of the values. This is unnecessary, and can cause use-after-free issues when taking references to the return values. Return references instead to optimize the implementation and avoid issues. The behaviour of the two functions is now undefined in case of an option type mismatch. The current implementation catches this with an assertion. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/cam/options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cam/options.h') diff --git a/src/cam/options.h b/src/cam/options.h index 83c409ae..0047b4f2 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -142,8 +142,8 @@ public: int toInteger() const; std::string toString() const; - KeyValueParser::Options toKeyValues() const; - std::vector toArray() const; + const KeyValueParser::Options &toKeyValues() const; + const std::vector &toArray() const; const OptionsParser::Options &children() const; -- cgit v1.2.1